w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
which is faster, saving chat history in a text file and display it or using mysql db to save chat history
For a real-world implementation, I wouldn't consider either one of these a good option, but it definitely could be fun to play with. Using files isn't going to scale as well as the db,well... as easily. But really, I'd look into just setting up a jabber server and play with that. Or maybe look into node.js.

Categories : PHP

Why doesn't bash history expansion work in functions?
This question has been asked here: use "!" to execute commands with same parameter in a script but in brief you need to set -o history set -o histexpand in your script to enable history expansion.

Categories : Linux

extra characters when scrolling through command history in bash
Figured this out. The problem was with the location of a in my PS1 prompt. The bad version: export PS1=" e[0;33m[!]e[me[0;32m[A w] e[m> The good version: export PS1=" e[0;33m[!]e[me[0;32m[A w]e[m >

Categories : Bash

Unix Subshell inheriting the command history from parent bash
Depending on your OS, .bash_profile may only be executed by login shells, while .bashrc is executed for non-login shells. So try putting shopt -s histappend PROMPT_COMMAND="history -a; history -n" in .bashrc instead of .bash_profile.

Categories : Python

Writing numbers 1-80 in JavaScript and writing text for certain multiples
Your problem is practically the Fizz Buzz test. Finding out the multiples is usually done by finding the remainder. Keep in mind that: nominator / denominator = quotient + (remainder / denominator) examples: 2 / 2 = 1 + ( 0 / 2 ) 3 / 2 = 1 + ( 1 / 2 ) 4 / 2 = 2 + ( 0 / 2 ) The modulus operator is defined as to find the remainder: nominator mod denominator = remainder from the examples above: 2 mod 2 = 0 3 mod 2 = 1 4 mod 2 = 0 Note that multiples of 2 have the remainder 0. The same thing goes with 3: 1 mod 3 = 1 -- 1 / 3 = 0 + ( 1 / 3 ) 2 mod 3 = 2 -- 2 / 3 = 0 + ( 2 / 3 ) 3 mod 3 = 0 -- 3 / 3 = 1 + ( 0 / 3 ) 4 mod 3 = 1 -- 4 / 3 = 1 + ( 1 / 3 ) 5 mod 3 = 2 -- 5 / 3 = 1 + ( 2 / 3 ) 6 mod 3 = 0 -- 6 / 3 = 2 + ( 0 / 3 ) The easiest way to find a multiple in Javascript

Categories : Javascript

writing text which reading and writing only one column
If this is a CSV file, which I can infer from the references to the csv file extension in the code, then you are much better off using a CSV parsing library such as opencsv, which will do all the hard work of parsing the file for you. You can then manipulate a CSV file object and save the result to the file.

Categories : Java

Awk/Bash writing script
This answer doesn't explore alternatives like using split or csplit to partition the file. Assuming that a=$(wc -l < $1), and that $3 contains the number of fragments (10 in the example written out longhand), then you can take your existing code and package it as one or two loops using seq to generate the numbers you need: a=$(wc -l < "$1") n=${3:-10} for i in $(seq 1 $n) do # a = number of records in file # n = number of parts the file is to be split into # p = part number of current part awk -v a=$a -v n=$n -v p=$i '{if (NR<(a/n*p)&&NR>=(a/n*(p-1))) print }' "$1" >"$1.$i" bash "$2" "$1.$i" & done wait # For all the background processes to complete That's the single loop version; you can create all the files first and then run a second

Categories : Bash

Need some help writing an if statement in UNIX bash scripting
Use grep -q grep -q "filename" .restore.info && echo "found match" or ! grep -q "filename" .restore.info && echo "not found"

Categories : Bash

Need help writing bash script, how to take a pw as argument and automate its entry
I'd read the variable in using read (in silent mode so that the characters typed aren't visible), then use it. Example: echo -n "Enter password: " read -s password gpg ... --password=$password

Categories : Linux

Writing a bash script to run a matlab program in UNIX?
You need one command what produces list of images one per line. Call it as list_images, or a filename what contains the list of images one cycle command, what reads the images one variable (calling it "image_name") comamnd to run matlab place, here the output should go Something like: list_images | while read image_name do matlab_command "$image_name" > "$image_name.output" done or better while read image_name do matlab_command "$image_name" > "$image_name.output" done < filename_with_images.txt Not really understand what you mean with the have amatrix images in a file, post an example of your input. EDIT for finding prj files in the curent directory find . -maxdepth 0 -name *.prj -print0 | while IFS= read -r -d '' image_name do matlab_command "$image_name

Categories : Bash

Given a XML file, I am writing Bash to parse it, but need to create a header and break up a date string?
Maybe this will work (first line adds header to new file, second line parses the date). If more parsing is necessary, take a look at sed. echo "Date Time source Format Specific data" > new.file sed 's/2013//13./g' old.file | sed 's///./g' >> new.file

Categories : Xml

Writing a bash script to push local files to Amazon EC2 and S3 - needs proper owner/permissions
After everything is done, you can put this in your script to execute commands remotely (e.g. chown, chmod and the like), ssh -l root -i ${BUILD_DIR}mykey.pem" $SERVER_IP "chown whateveruser:whatevergroup $SERVER_DIR" Syntax: ssh -l root -i key $SERVER_IP "your command"

Categories : Bash

PayPal Sandbox history redirects to REAL history
It's a known issue - sorry. Trying to change the URL to the Sandbox one still redirects you to the Live site and, occasionally for whatever reason, a security certificate page. A fix is coming soon. If you want to be updated on the issue as it goes on you create a ticket at PayPal.com/mts, let me know what the ticket number is, and I can grab it. Edit: This should be resolved now. I cleared my cache and cookies, closed the browser, and tried it out. I was able to view the transaction history in the Sandbox.

Categories : Paypal

How to detect Backbone.History referer (history length)
You can do the following: Router initialise function - this.on("all", this.storeRoute); this.history = []; Then the storeRoute function (also in router) - storeRoute: function() { return this.history.push(Backbone.history.fragment); } The also in router - previous: function(){ if (this.history.length > 1) { return this.navigate(this.history[this.history.length - 2], true); } } So, then you can just call yourApp.router.previous() at any time!

Categories : Javascript

How to keep documentation history separate from source history?
You can do à la GitHub with their gh-pages branch: git checkout --orphan project-doc The branch will have its own history while being in the same repository.

Categories : GIT

history.js - initial page not being stored in history
You can to call statechange event by jQuery into the: $(document).ready(function(){ ... jQuery(window).trigger('statechange'); });

Categories : Javascript

Pass content of file in variable into bash script - without writing the file down
You need one more <: ./script -a <<<"$CONTENT" <<< is called a herestring, and takes the following string and passes it as the standard input.

Categories : Linux

writing text into a textbox
I'd create a public property in Form1 that you can use. Form1.cs public string TextBoxText { get { return myTextBox.Text; } set { myTextBox.Text = value; } } You can then set the value from another class. AnotherClass.cs myForm1.TextBoxText = "Current server status"; How you get access to myForm1 depends on how you're calling the other class. For example, you could pass the form into the other class's constructor. private Form1 myForm1 = null; public AnotherClass(Form1 mainForm) { myForm1 = mainForm; myForm1.TextBoxText = "Current server status"; }

Categories : C#

Writing a text in a QPixmap
Drawing to a QPixmap is done through a QPainter. For example: QPixmap pix = ...; QPainter painter( &pix ); painter.setFont( QFont("Arial") ); painter.drawText( QPoint(100, 100), "Hello" ); This is a very basic usage, look at the QPainter documentation for more information.

Categories : C++

writing to text file using BufferedReader
As per your problem statement, you need to take input from a file, do some processing and write back the processed data in the same file. For this, please note the below points: You may not create a file with same name in a directory, so you must create the new file at some other location; or write the content into different file and later rename it after deleting original one. While your file is open for reading, modifying the same file is not a good idea. you could use below approach: Read the content of the file and store in a data structure liek Arrays, ArrayList. Close the file. Process the data stored in the data structure. Open the file in write mode (over-write mode rather than append mode) Write back the processed data into the file.

Categories : Java

SQL - one text box writing to multiple fields
For your question I can suggest this solution: 1) You need to now that there is any record for your current user: SELECT COUNT(*) FROM Profiles WHERE Username = {0} -- Set {0} = Session"Username" If result is null or 0 it means that there is no record else yes: . . . 1. No) Add a new record to your table without teams: . . . . .INSERT INTO Profiles VALUES ({0}, null, null) -- Set {0} = Session"Username" 2) Now you have a record of your current user in Profiles. so : After 1st. submit: UPDATE Profiles SET Team1 = {1} WHERE Username = {0} -- Set {0} = Session"Username"` & Set {1} = Team1.Text And after 2nd. submit: UPDATE Profiles SET Team2 = {1} WHERE Username = {0} -- Set {0} = Session"Username"` & Set {1} = Team2.Text

Categories : SQL

Writing a table in a text file
Use csv.writer to write CSV-style data to files. Example: import csv import re pattern = re.compile('([0-9]*:[0-9]*:[0-9]*) Current Track Playing = ([^-]*?) - ([^-]*)$') csv_file = open('music.csv', 'wb') csv_writer = csv.writer(csv_file, delimiter=';', quotechar='"', quoting=csv.QUOTE_MINIMAL) with open('music.log', 'r') as music_log: for line in music_log: timestamp, song, artist = pattern.match(line.strip()).groups() csv_writer.writerow([timestamp, song, artist]) csv_file.close() (This assumes you've already done the stripping of the numerical IDs from the log you asked about in another question). Output: 08:04:10;Skinny Genes;Eliza Doolittle 08:07:09;Keep On Walking;Scouting For Girls

Categories : Python

Writing a text file using python
with open('somefile.txt', 'w') as fp: fp.write('''MY_FILE = E: est.jpg BAND_SUBSET = ( 1 0 0 ) SPATIAL_SUBSET1 = ( 25.0 50.0 ) SPATIAL_SUBSET2 = ( 25.0 50.0 ) PARA1 = ( 0.0 0.0 0.0 0.0 0.0 0.0 ) END = END''')

Categories : Python

List the history of text field while typing on the field in an Eclipse RCP application
You can use org.eclipse.jface.fieldassist.AutoCompleteField for this. For a text field it might look like this: new AutoCompleteField(text, new TextContentAdapter(), new String [] {"proposal 1", ...});

Categories : Java

Writing packet information into text file
Probably because you are missing a comma before " ": ---------------------------------------------------vv----- file:write(tostring(srcadd), " ", tostring(dstadd), " ") It may be useful to check for file value returned by the open call. I don't see any other problems with the script; if you still have issues, I have a page on debugging Wireshark Lua scripts that may help.

Categories : Networking

Writing post values to a text file
This works completely on my localhost. I haven't recreated the full scenario with your HTML but it works now. Just remember to set the file permissions to read/write and also make sure you do it one step at a time. For example, start off with this code and make sure you get the file name file.txt with the text you wanted. Then take it to the next level by including the HTML bit. <?php $fname = "Skippy"; $message = "name is :" . $fname. " "; $file = 'file.txt'; $fd = fopen($file, "a"); if ($fd) { fwrite($fd, $message . " "); fclose($fd); } ?>

Categories : PHP

Writing Styled Text to a .docx file
For my example I assume you'd use a HTMLEditorKit in your JTextPane. I would then parse the StyledDocument of the pane and set the textruns accordingly. Of course this is just a starter, you'd need to parse all the possible styles and convert them yourself in the loop below. I've to admit, that I've never done something with the HTMLEditorKit and therefore I don't know how to handle the CSS.CssValues properly. import java.awt.Color; import java.io.FileOutputStream; import java.lang.reflect.Field; import java.util.Enumeration; import javax.swing.*; import javax.swing.text.*; import javax.swing.text.html.*; import org.apache.poi.xwpf.usermodel.*; public class StyledText { public static void main(String[] args) throws Exception { // prepare JTextPane pad = new JTextPa

Categories : Java

Writing text to txt file in python on new lines?
How about something like this: import urllib2 url = 'http://www.google.com' data = '' try: data = urllib2.urlopen(url).read() except urllib2.URLError, e: data = 'PAGE 404: It Doesnt Exist ' + e with open('outfile.txt', 'w') as out_file: out_file.write(data)

Categories : Python

Continuously writing to a text file in Android
At time of writing your link appears to be for a different language, and that version seems to be down. The English version is still up and can be found here: http://developer.android.com/training/basics/data-storage/files.html In the meantime, I believe you have to access the raw directory which contains your text file (create a raw directory within the res directory if you don't already have one and put the text file there). The code to access the text file is getResources().openRawResource(resourceName) (as stated in this question: http://stackoverflow.com/a/2856501/555544) - I believe resourceName is the id of your text file as stated in your R file (e.g.: R.raw.foo) - this is how Android can find files in your directories. Then, just do your file I/O as you normally do. Let me know

Categories : Java

String Writer writing into text file
The issue is in Submit Code protected void btnShow_Click(object sender, EventArgs e) { System.IO.StreamWriter stringWriter= new System.IO.StreamWriter("c:\test.txt"); foreach (Control control in Panel1.Controls) { var textBox = control as TextBox; if (textBox != null) { if (string.IsNullOrEmpty(textBox.Text)) { textBox.Style["visibility"] = "hidden"; } stringWriter.Write( textBox.Text+","); // Write text to textfile. } // end of if loop } Reference MSDN and MSDN

Categories : C#

alternative to gdi when writing text editor in winapi
GDI is not too fast. But probably for editor, it should be sufficient. It also depends on the inteligence of the paint algorithm. When being edited, for example, you should only re-render the affected line(s). Even when inserting new lines, you may just scroll most of the ones below with ScrollWindow() or ScrollWindowEx(). As an alternative you may look at Uniscribe (USP10.DLL). However I am not sure whether it relies on GDI or not. It is more or less replacement of TextOut() and similar GDI functions to support properly different scripting systems, including aspects like right-to-left reading, mixtures of left-to-right and right-to-left (e.g. arabian with embedded European personal names etc.) Then there is also DirectWrite, which is supposed to be used together with Direct2D. That shou

Categories : Windows

Fix newlines when writing UTF-8 to Text file in python
If you use python 2, then use u" " to append newline, and encode internal unicode format to utf when you write it to file: file_object.write((n+u" ").encode("utf")) Ensure n is of type unicode inside your loop.

Categories : Python

Writing to text file with automatic spacing
Try padding the strings using String.format() This question should show you how it works: How can I pad a String in Java? Pad each of the elements into strings of equal length before you write to the file.

Categories : Java

How to change the fontsize when writing to a text file
Supposing you are editing your text in a JTextArea you might do this: this.textArea.setFont(new Font("Arial", Font.PLAIN, 12)); //the code comments itself if you want bold then write Font.BOLD As someone already told you, unfortunately plain .txt files don't contain formatting. If you need to format the text, you should change format and try HTML.

Categories : Java

How to add a break to a line while writing to a text file
Your underlying QIODevice (the file) is not really working in text mode. Use QIODevice::Text when opening the file that is used with the stream QFile file( filename , QIODevice::Text ); ... QTextStream stream( &file); For a text stream, both " " and ' ' should work. You may opt for std::endl (or, more precisely, its counterpart in Qt) instead, but this is not really necessary. " " and ' ' will produce proper result regardless of the OS, assuming your output stream is indeed a text stream, and assuming that your generate file on the same platform that you use to inspect it. (The remarks asserting that " " must be used on Windows are incorrect.) An example of a situation when you indeed will have to use " " is when you are trying to generate a Windows text file on a POSIX system.

Categories : C++

c# Console App Text Aligin when writing out list
try Console.WriteLine(string.Format("{0} {1} {2} ", ite, pri, idd)); instead of Console.WriteLine("{0} {1} {2} ", ite, pri, idd); This should space things out a bit. Depending on how wide your tab character is, and how many digits / characters are in your string you might need fewer or less than three tabs.

Categories : C#

Writing to text file doesn't match
I think that you should increment recordsWritten in the last step: if (numberofCommas > 8) { stringWriter.Write(textBox.Text); numberofCommas = 0; recordsWritten++; } Here is a better way to do it using Linq: var textBoxes = Panel1.Controls.OfType<TextBox>().Select((t, i) => new { TextBox = t, Index = i }).ToList(); foreach (var tb in textBoxes) { if (string.IsNullOrEmpty(tb.TextBox.Text)) tb.TextBox.Style["visibility"] = "hidden"; tb.TextBox.Enabled = false; } foreach (var line in textBoxes.GroupBy(e => e.Index / 10) .Select(e => string.Join(", ", e.Select(a => a.TextBox.Text).ToArray()))) stringWriter.WriteLine(line);

Categories : C#

StreamWriter Replace while Writing to a new Text File
You can replace a character with a string by simply converting the character to a string and then calling the Replace(string, string) overload. For instance: wwrite.WriteLine((i + 1).ToString() + "^" + listView1.Items[i].SubItems[3].Text.Replace("x0A", " ")); You seem to be confused about strings. Strings are simply a collection of characters. So " " and ' ' are essentially the same value. The first stores the value as a single character string and the second stores the same value as a character. If you want to replace a new-line character with the actual string (as two separate characters), you need to escape the backslash, for instance: s = s.Replace(" ", "\n"); Or: s = s.Replace(" ", @" ");

Categories : C#

writing new lines to a text file in powershell
`n is a line feed character. Notepad expects linebreaks to be encoded as `r`n (carriage return + line feed, CR-LF). Open the file in some useful editor (SciTE, Notepad++, UltraEdit-32, Vim, ...) and convert the linebreaks to CR-LF. Or use PowerShell: (Get-Content $logpath | Out-String) -replace "`n", "`r`n" | Out-File $logpath

Categories : Powershell

Writing to a Static Text Box in a Panel - MATLAB
Children is a field so if you want the children you can try get(handles.uipanel2,'Children') and it will give you an array with handles to the children. It will look like numbers to you in the same way that the handle to uipanel2 looks like a number. Here's an example: function testGUI fig = figure(1); panel = uipanel(fig); tbox = uicontrol('Style','text','String','hello','parent',panel); ch = get(panel,'Children') get(ch,'Type') get(ch,'String') end It shows how to get the Children of the panel object with ch = get(panel,'Children') which should print something to console that looks like: ch = 182.0011 And to show you that this ch is in fact a handle to the static textbox that is a child of the panel, I've printed out the type and string of ch to con

Categories : Matlab



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.