w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Putting a fake loading screen to give the impression that the calculation take time?
The easiest approach is; when a user clicks the button: show a div that contains a loading image or such (tip: use jQuery library) start a timer when timer finishes: hide the div perform above function

Categories : Javascript

An API rate limiter
This is quite fine in my opinion. Except that, there is a bug in this code. This is because what if each request is done more than a second after one another? It will never go inside that if block. Thus, some kind of memory leak because the _requests will grow larger over time and possibly never be cleared if my scenario above always happens. Example: for (int i = 0; i < 100; i++) { RateLimiter.CheckLimiter(); Thread.Sleep(2000); } What you can do is to remove entries in your _requests that are exceeding the 1 second rule like adding this line at the end of your method. if (_requests.Count != 0) { //remove irrelevant/expired entries _requests.RemoveAll(date => (DateTime.Now - date).TotalMilliseconds >= _perMillisecond); }

Categories : C#

Error with the limiter {} in regexp
Remove the whitespace so it looks like... if (rif.match("^(j|J)(-)([0-9]{8})(-)([0-9]{1})$")) { alert("OK"); } else { alert("NO"); } See this fiddle: http://jsfiddle.net/CPWjv/

Categories : Jquery

PHP/MySQL SELECT LIMITER issue
you are missing page 1 because of your if condition. if(isset($_GET["p"]) && is_numeric($_GET["p"]) && $_GET["p"] > 1) { this is set to skip the paging logic unless of the page is greater than 1. So it misses page = 1. based on your code only if p is 0 your code will render 0,9 if the p = 1 then your code renders 9,9

Categories : PHP

Cannot send session cache limiter?
You have to put session_start(); on the top of your php page. is this the top? for example: <html> <head> //stuff </head> <body> //beginning of page: <?php session_start(); //rest of code. ?> </body> </html> otherwise: <?php if(!isset($_SESSION['login'])){ session_start(); header("Location:login.php"); exit(); } include_once("action.php"); ?> NOTE: this probably fixes your first error. (Line 1)

Categories : PHP

Codeigniter word limiter closing html tag
First, you need to remove HTML tags from the string with strip_tags() function, then you can use word_limiter() helper function safely: echo word_limiter(strip_tags($item['text']), 25);

Categories : PHP

Random Cannot send session cache limiter - headers already sent
Typically, I find that "headers already sent" errors are actually whitespace errors. Maybe check any files that are shared between all of these pages and see if there is an extra line break or space after a closing ?> tag. Generally I try to avoid using closing PHP tags at the end of files since they are discarded by the parser anyway.

Categories : PHP

How to stream input line by line in UNIX, perform commands on each line, and immediately return output?
You can use echo "${#line}" to know the length of a string. Reading the file with a while read... will do the rest: $ cat file hello my name is fedor qui $ while read line; do echo "${#line}"; done < file 5 7 8 3 0 In a nicer format: while read line do echo "${#line}" done < file

Categories : Shell

Draw straight line and create curve line dragging line
Second touch - hold a variable to track your state. Curve - don't try to change a path, just use the start and end of the first line and create a UIBezierPath to draw as the user moves the touch point. Move the bezier to the start point, then use addCurveToPoint:controlPoint1:controlPoint2: using the end point and the current touch location. To make it really fun, allow the user to touch with 2 fingers while drawing the second line and then you have values for both of the control points.

Categories : IOS

My code is working and the first line is displaying correctly but the second line is concatenated with the first line etc
Change $(".Weight").text(weight + unit); to $(".Weight", this).text(weight + unit); so that only the .Weight cell of the current row is changed. A prevision following comments : it's useless to cache selectors here, there wouldn't be any noticeable gain and it makes the code harder to read and maintain using children is slower, which isn't very important. What's important is that using children departs from the semantic use of classes, it makes your code rely on the fact the .Weight element is a direct child and not, for example a span in a td. That's exactly the same reason than why you should generally prefer closest over parent.

Categories : Jquery

reading file line by line , modify the line and write this line on same file. Python
Because you've used .split on the line, you're working with a list of strings. While a string is conceptually just a list of characters, it's still not a list of strings. Try using the .join method of a string to join your array before you write it out, for example: ''.join(["one, two"]) == "onetwo"

Categories : Python

unix command line cut and remove new line, unwrap next line
This awk one liner can do it: $ awk '{if ($0 ~ /&$/) {getline a; print $0,a} else {print }}' file it gets the lines ending with & and joins them with the next one. Otherwise just prints the line. Test $ awk '{if ($0 ~ /&$/) {getline a; print $0,a} else {print }}' file A7233334 PALLETS 2 11.000 EACH 2331 Storm Supply 247.5000 2,722.50 2,722.50 4144 Gentro Sales 225.0000 2,475.00 2,475.00 5155 Wacca Outfit 225.0000 2,475.00 2,475.00 6661 Acme Warehouse & Fuller Supply 225.0000 2,475.00 2,475.00 1661 McHugh & Donaldson

Categories : Unix

Python 3 - Reading line by line from a textfile and doing action for each line
urlFile = "path/to/file" urls = open(urlFile).readLines() for url in urls: doAction(url) OR you could just put it all in the url file reading loop; with open(urlFile) as f: for line in f: doAction(line)

Categories : Python

Bash: loop through file line by line, find specific string and append to each subsequent line until same string is found
If I have your requirements right, this little awk program will work: awk '/^AB1/{ab1=$0;next}/^AB2/{print $0, ab1}' That will do nothing with any line which doesn't start with AB1 or AB2 and it fails to check for equality of the 12-character string following the AB1/AB2. I couldn't tell if you require that check.

Categories : Regex

Extract a numeric substring and another line as variables from multi-line text file
You could use the following regex for the second line: ^.*(d{6})[^d].*$ Here, the first named sub-group would denote the digits of interest. For example, using Notepad++, Orginal text: Replace options: Resulting text: The regex should remain more or less the same across environments. You might need to simply change the way the named subexpression ($1 here) is referenced.

Categories : Regex

How to Calculate and Draw Dimension Line (line with perpendicular end lines) in iOS using Core Graphics?
The following code computes a vector of length 1 that is perpendicular to the line from p = (x, y) to p1 = (x1, y1): CGPoint p = CGPointMake(x, y); CGPoint p1 = CGPointMake(x1, y1); // Vector from p to p1; CGPoint diff = CGPointMake(p1.x - p.x, p1.y - p.y); // Distance from p to p1: CGFloat length = hypotf(diff.x, diff.y); // Normalize difference vector to length 1: diff.x /= length; diff.y /= length; // Compute perpendicular vector: CGPoint perp = CGPointMake(-diff.y, diff.x); Now you add and subtract a multiple of that perpendicular vector to the first point to get the endpoints of the first marker line at p: CGFloat markLength = 3.0; // Whatever you need ... CGPoint a = CGPointMake(p.x + perp.x * markLength/2, p.y + perp.y * markLength/2); CGPoint b = CGPointMake(p.x - perp.x * mar

Categories : IOS

Objective C - Create text file to read and write line by line in Cocoa
Well, to create a file, just use [[NSFileManager defaultManager] createFileAtPath:@"Your/Path" contents:nil attributes:nil]; This creates an empty file, which you can write to or read from. To write text (or XML), just use NSString's writeToFile:atomically:encoding:error: method like this NSString *str = //Your text or XML [str writeToFile:"Your/Path" atomically:YES encoding:NSUTF8StringEncoding error:nil]; To read from a file, just make an NSString with the contents of that file NSString *contents = [NSString stringWithContentsOfFile:@"Your/Path"]; or, if it does not contain a string, get an NSData object from the file NSData *contents = [NSData dataWithContentsOfFile:@"Your/Path"];

Categories : Objective C

Draw / Write on an image more than one line - EmguCV (OpenCV) does not recognize new line char
You can always make your own function that parses the paragraph into individual lines and then produce the y-displacement needed for each row. If I remember correctly, the default font size is 16 pixels. void myDrawMultiLineText(string InputParagraph, Point Origin) { vector<string> LinesOfText = myParse(InputParagraph," "); for (int i=0;i<LinesOfText.size(); ++i) DrawText(CurrentLine[i], Origin.x, Origin.y + i*16); }

Categories : C#

Matplotlib fill blank image line by line, when I receive data from socket
It's unnecessary to create a new image every time new data arrives from the socket. You can create a single image on initialisation, then update the values in the array from the data you are receiving: # on initialisation self.im = imshow(np.zeros((x,y)),cmap='gray',interpolation='nearest', origin='lower') ... # on update self.im.set_data(self.values) self.im.set_clim(self.values.min(),self.values.max()) self.im.figure.canvas.draw()

Categories : Python

Java vertical line behind text? Like the line in an editor that indates where a page ends
I'm not entirely sure what you're doing, but it seems to me like you could get a decent solution by adding an element in your JList that looks something like "-------------------" where a page break would be so that it displays. I'm not sure if that's what you're looking for though.

Categories : Java

How to read the input(line by line) from a multiline Tkinter Textbox in Python?
From the document, the get method on tkinter.text will just return the string, including the new line . You can not treat the tkinter.text as file, but you can use other ways. Read them all and split them into a list. Loop the list then. def retrieve_input(): text = self.txt.get('1.0', END).splitlines() for line in text: ... Using io.StringIO to emulate a file, but in this case it will not strip the newline. def retrieve_input(): text = io.StringIO(self.txt.get('1.0', END)) for line in text: line = line.rstrip() ...

Categories : Python

sending text file from server to client line by line in winsocks
You need to also send a newline. getline reads all characters until a newline, but doesn't store the newline in the string. So when you send the string, it doesn't have a newline. You can either send a " " on its own, but probably better to add a newline to the existing string. E.g. : stringToUpper(STRING); STRING += " "; ...

Categories : C++

How to read data from Excel and write it to text file line by line?
You should open the output.txt file with append mode: file = open("Output.txt", "a") Also, you should do this before entering the loop, and it should be closed after that loop. Update: In cases like this one, you could use with instead of closing the file handle at the end. Also including the good suggestion made by @Josh in his own answer, the code could be this: import xlrd import os.path wb = xlrd.open_workbook(os.path.join('D:TRB 2014 Data','SPS1 demo data.xlsx')) wb.sheet_names() sh = wb.sheet_by_index(0) i = 1 with open("Output.txt", "a") as my_file: while sh.cell(i,11).value != 0: Load = sh.cell(i,11).value all_d = sh.col_values(i, 13, 19) DB1 = Load + " " + (" ".join(all_d)) my_file.write(DB1 + ' ') i += 1

Categories : Python

Why can one line of code work, but then the same line throws a null pointer exception later?
On the third line of your onStart method you are setting the context to the activity. Try setting it to the context instead. this.context = getActivity().getApplicationContext();

Categories : Java

Node.js: Why on data event from cmd /c dir spawn doesn't output 'line by line'?
Because this is just a pure data stream from the child process's standard output. There is no knowledge of whether that data is in any particular format, or whether it will contain any specific characters at all. So the data is treated like a stream of bytes and handled in chunks with no regard for the content or meaning of those bytes. That's the most general form of piping data around the system. Note, however, that there are wrapper streams that will buffer the raw data stream and give you a series of lines of text. You will find many modules for this on npmjs.org

Categories : Node Js

R - Export line by line while transforming data, adding "" in places and not others while also removing NA
If I understand correctly, I think the function write.table() does everything you want. Rather than "transforming" your data as you write it, cant you just modify the dataframe until it has the format you want? For example, to get the UserID column to write out as a string, just convert that column to strings before writing the table, e.g. myData$UserID<-as.character(myData$UserID) Once the dataframe is correctly formatted, it should be as easy as write.table(myData,outFilePath,sep=",",na="",row.names=FALSE) Note the na="" argument, which tells it how to format NA values. For the footer row, you could deal with that separately, and use the "append=TRUE" argument.

Categories : R

Highcharts Line - When Y axis min is set to 0, connecting line isn't shown for consecutive 0 values
Unfortunately it is known bug, reported to our developers here https://github.com/highslide-software/highcharts.com/issues/1687 You can try to set min value or threshold: http://api.highcharts.com/highcharts#plotOptions.series.threshold http://api.highcharts.com/highcharts#yAxis.min

Categories : Highcharts

search for a string and delete duplicates and add new line to second and last line of a text using bash
From what I can tell, you want to delete the second occurrence of <?xml ... ?> and wrap everything in the <frame> tag using only command line tools. This can all be done with a sed one-liner sed '0,/<?xml.*>/! s/<?xml.*>//g' -e '2i <frame>' -e '$a </frame>' The first expression deletes all <?xml ... ?> tags excluding the first one, the second expression inserts <frame> at line 2, and the third expression appends </frame> at the end.

Categories : Xml

Removing the new line character from javascript and making the data come in single line
Don't use new RegExp. Just use the string replace method. justiread..replace(/( | | )/gm,"") The "g" switch is global replace, "m" means it should happen more than once. See http://www.textfixer.com/tutorials/javascript-line-breaks.php

Categories : Javascript

AIX Shell Script - Formatting a long line of 255 Characters into a 10 line paragraph
How about this? echo "Life is not about searching for the things that could be found. It's about letting the unexpected happen. And finding things you never searched for. Sometimes, the best way to move ahead in life is to admit that you've enough" | fmt -w 30 Result: Life is not about searching for the things that could be found. It's about letting the unexpected happen. And finding things you never searched for. Sometimes, the best way to move ahead in life is to admit that you've enough

Categories : Shell

Assigning variables to values in a text file with 3 columns, line by line
while read x y z; do echo x=$x y=$y z=$z done < input.txt The above requires that none of your columns contain any whitespace. EDIT: In response to comments, here is one technique to handle numbering the lines: nl -ba < input.txt | while read line x y z rest; do ~/data/standard/MNI152_T1_2mm -mul 0 -add 1 -roi $x 1 $y 1 $z 1 0 1 point -odt float > NewFile$line done

Categories : Bash

What's the advantage of having multi-line & single-line string literals in python?
The advantage of having to be explicit about creating a multi-line string literal is probably best demonstrated with an example: with open("filename.ext) as f: for line in f: print(line.upper()) Of course, any decent syntax-highlighting editor will catch that, but: It isn't always the case that you're using a syntax-highlighting editor Python has no control over what editor you are using. Two of Python's design principles are that errors should never pass silently, and explicit is better than implicit. Outside docstrings, multi-line strings are rarely used in Python, so the example above is much more likely to occur (everyone mistypes sometimes) than the case where you want a multi-line string, but forgot to explicitly say so by triple-quoting. It's similar to Pyth

Categories : Python

Groovy - Adding a line in middle of a file without modifying new line characters
I believe your solution handles this case, but keep in mind this can get tricky for input files such as: // Dangerous comment // // import com.oldcompany.Bogus; import com.foo.Example; public MyClass { } However, both your solution (and mine) will fail if there is no import: // random comment // public MyClass { } Assuming there must be an import, here is one way to do it, using regular expressions: def addIfRequired = { def directory, def filePath -> def inputFile = new File(filePath) boolean containsPackage = false; List<String> lines = inputFile.readLines(); for (def eachLine : lines) { eachLine = eachLine.trim(); if (eachLine.startsWith("package ")) { containsPackage = true break } else if (eachLine.st

Categories : Groovy

how to center a semi transparent img on a horizontal line, without letting appear the line below the image?
Couldn't you just make an image in Photoshop that has the line and all the specifications you want. Something like <hr><img src="SRC"><hr> wouldn't work because it would break into two lines (see this fiddle). EDIT: According to your updated fiddle, you figured it out. In terms of better ways of doing this, I think that your way would work, although you would want to test it on a mobile device or shrunken browser to test its responsiveness. When I test its responsiveness on the fiddle, it seems to work in a smaller browser, although it breaks when it gets too small (about 40 px); however, no screen is so small that it would break. Long story short, use the fiddle you posted. http://jsfiddle.net/j4eH8/4/

Categories : CSS

how to read multiline output command line by line, in a shell script?
Maybe I found a different solution, where I can use variables also outside the loop I have to change the default IFS to newline echo Searching for android virtual devices ... IFS=$' '; for l in $(${PROGDIR}/android list avd) ; do VAR1=$(echo $l | cut -d: -f1 | sed -e 's/s*//'); #sed removes trailing blanks if [ $VAR1 == "Name" ]; then NUM_AVD=$(($NUM_AVD+1)); fi; done echo "NUM_AVD=$NUM_AVD" In this case NUM_AVD is correctly 2

Categories : Shell

Visual Basic - Writing / Overwriting into a text line adds a new line
Going on the information from the question and comments, it seems that your file will end up with an additional linefeed at the end in both cases (ie. both for new and modified files). The reason for this is that you're using the WriteLine method, which will append a newline at the end of the text it writes, even if that text already ends with a newline. Simply change the code to use the Write method instead of the WriteLine method and you should end up with a file that contains only the text passed to the method.

Categories : Visual Studio 2010

linux shell: prepend or append text to next line after matching line
If you're confused on the general text-piping linux applications, I would recommend going through this exercise on the Learn Linux the Hard Way course. Should take 4-5 minutes and help quite a bit.

Categories : Linux

indexing of large text files line by line for fast access
Take the 43GB file in chunks that fit comfortably in memory and sort on the subject. Write the chunks separately. Run a merge sort on the chunks (sorted by subject). It's really easy: you have as input iterators over two files, and you write out whichever input is less, then read from that one again (if there's any left). Now you just need to make one pass through the sorted data to gather the groups of subjects. Should take O(n) space and O(n log n) time, which for this sort of thing you should be able to afford.

Categories : Scala

In Java, how do I read the content line by line of another console application that's running?
ProcessBuilder in java provides a way to execute an external OS command and pipe input and read output from the external command. Here is a sample which does that: List<String> command = new ArrayList<String>(); command.add("/path/to/Blockland.exe"); command.add("Other arguments"); ProcessBuilder procBuilder = new ProcessBuilder(command); Process proc = procBuilder.start(); ProcessOutputReader outputReader = new ProcessOutputReader(proc.getInputStream()); ProcessOutputReader errorReader = new ProcessOutputReader(proc.getErrorStream()); Thread out = new Thread(outputReader); out.start(); Thread error = new Thread(errorReader); error.start(); proc.waitFor(); Where ProcessOutputReader is a class that implements Runnable. It starts reading from the stream provided in

Categories : Java

javascript how to read line by line from a local text fie and display in a listbox
You can't access to the local file system, because that would mean you can read all the files on one's computer. Howewer, you can get a particular file when the user drag and drops that file into an element. Here's an example that shows you the content of the file if it is a txt document: http://html5demos.com/drag-anything

Categories : Javascript



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