Tutorial by Examples: c

This function copies data between two streams - void copy(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[8192]; while ((bytesRead = in.read(buffer)) > 0) { out.write(buffer, 0, bytesRead); } } Example - // reading from System.in and ...
Let's say you have this line of code: printf("Hello, world!\n"); Now say you want to change the text to "Program exiting." CommandBufferMnemonicci"printf("¦");change in the ".Program exiting.\n<esc>printf("Program exiting.\n");
git log master..foo will show the commits that are on foo and not on master. Helpful for seeing what commits you've added since branching!
Sometimes you will make a mistake with a lengthy macro, but would rather edit it than re-record it entirely. You can do this using the following process: Put the macro on an empty line with "<register>p. If your macro is saved in register a, the command is "ap. Edit the ma...
Using else we can perform some task when the condition is not satisfied. But what if we want to check a second condition in case that the first one was false. We can do it this way: a = 9; if mod(a,2)==0 % MOD - modulo operation, return the remainder after division of 'a' by 2 disp('a is ev...
When we use a condition within another condition we say the conditions are "nested". One special case of nested conditions is given by the elseif option, but there are numerous other ways to use nested conditons. Let's examine the following code: a = 2; if mod(a,2)==0 % MOD - modulo o...
To check if a required gem is installed, from within your code, you can use the following (using nokogiri as an example): begin found_gem = Gem::Specification.find_by_name('nokogiri') require 'nokogiri' .... <the rest of your code> rescue Gem::LoadError end However, this can ...
This can be easily accomplished by calling Enumerable#to_a on a Range object: (1..10).to_a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (a..b) means that it will include all numbers between a and b. To exclude the last number, use a...b a_range = 1...5 a_range.to_a #=> [1, 2, 3, 4] or...
Suppose we want to select a word with a surrounding white space, use the text object aw for around a word using visual mode: Got to normal mode by pressing ESC Type vaw at the beginning of a word This will select the word with white space
You may sometimes want to change the size of a split or vsplit. To change the size of the currently active split, use :resize <new size>. :resize 30 for example would make the split 30 lines tall. To change the size of the currently active vsplit, use :vertical resize <new size>. :vert...
Quite often it's necessary to send/upload a file to a remote server, for example, an image, video, audio or a backup of the application database to a remote private server. Assuming the server is expecting a POST request with the content, here's a simple example of how to complete this task in Andro...
Consider the program implicit none integer f, i f(i)=i print *, f(1) end Here f is a statement function. It has integer result type, taking one integer dummy argument.1 Such a statement function exists within the scope in which it is defined. In particular, it has access to variables an...
This substitute command can use Regular Expressions and will match any instance of foo followed by any( one ) character since the period . in Regular Expressions matches any character, hence the following command will match all instances of foo followed by any character in the current line. :s/foo....
You use the condition attribute to specify the condition to use. <cfset myVar=false> <cfloop condition="myVar eq false"> <cfoutput> myVar = <b>#myVar#</b> (still in loop)<br /> </cfoutput> <cfif RandRange(1,10) eq 10> ...
You can loop over a Structure or COM collection. <cfset myBooks = StructNew()> <cfset myVariable = StructInsert(myBooks,"ColdFusion","ColdFusion MX Bible")> <cfset myVariable = StructInsert(myBooks,"HTML","HTML Visual QuickStart")> <cf...
Exporting a database is a simple two step process: sqlite> .output mydatabase_dump.sql sqlite> .dump Exporting a table is pretty similar: sqlite> .output mytable_dump.sql sqlite> .dump mytable The output file needs to be defined with .output prior to using .dump; otherwise, the...
We can run custom JavaScript on a UIWebView using the method stringByEvaluatingJavaScriptFromString().This method returns the result of running the JavaScript script passed in the script parameter, or nil if the script fails. Swift Load script from String webview.stringByEvaluatingJavaScriptFromS...
Instead of web pages, we can also load the document files into iOS WebView like .pdf, .txt, .doc etc.. loadData method is used to load NSData into webview. Swift //Assuming there is a text file in the project named "home.txt". let localFilePath = NSBundle.mainBundle().pathForResource(&...
Creating Gradient UIImage with colors in CGRect Swift: extension UIImage { static func gradientImageWithBounds(bounds: CGRect, colors: [CGColor]) -> UIImage { let gradientLayer = CAGradientLayer() gradientLayer.frame = bounds gradientLayer.colors = colors ...
+ (CALayer *)gradientBGLayerForBounds:(CGRect)bounds colors:(NSArray *)colors { CAGradientLayer * gradientBG = [CAGradientLayer layer]; gradientBG.frame = bounds; gradientBG.colors = colors; return gradientBG; }

Page 343 of 826