Tutorial by Examples

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....
Use the from and to attributes to specify how many iterations should occur. The (optional) step attribute allows you to determine how big the increments will be. <cfloop from="1" to="10" index="i" step="2"> <cfoutput> #i#<br />...
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 the results of a ColdFusion query. <cfquery name="getMovies" datasource="Entertainment"> select top 4 movieName from Movies </cfquery> <cfloop query="getMovies"> #movieName# </cfloop>
You can use the (optional) delimiters attribute to specify which characters are used as separators in the list. <cfloop list="ColdFusion,HTML;XML" index="ListItem" delimiters=",;"> <cfoutput> #ListItem#<br /> </cfoutput> <...
You can loop over a file. <cfloop file="#myFile#" index="line"> <cfoutput> #line#<br /> </cfoutput> </cfloop>
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; }
Python multithreading performance can often suffer due to the Global Interpreter Lock. In short, even though you can have multiple threads in a Python program, only one bytecode instruction can execute in parallel at any one time, regardless of the number of CPUs. As such, multithreading in cases w...
Use threading.Thread to run a function in another thread. import threading import os def process(): print("Pid is %s, thread id is %s" % (os.getpid(), threading.current_thread().name)) threads = [threading.Thread(target=process) for _ in range(4)] for t in threads: t.sta...
Use multiprocessing.Process to run a function in another process. The interface is similar to threading.Thread: import multiprocessing import os def process(): print("Pid is %s" % (os.getpid(),)) processes = [multiprocessing.Process(target=process) for _ in range(4)] for p in...
As all threads are running in the same process, all threads have access to the same data. However, concurrent access to shared data should be protected with a lock to avoid synchronization issues. import threading obj = {} obj_lock = threading.Lock() def objify(key, val): print("O...
Code running in different processes do not, by default, share the same data. However, the multiprocessing module contains primitives to help share values across multiple processes. import multiprocessing plain_num = 0 shared_num = multiprocessing.Value('d', 0) lock = multiprocessing.Lock() ...

Page 552 of 1336