Tutorial by Examples: c

An anonymous function is, as the name implies, not assigned a name. This can be useful when the function is a part of a larger operation, but in itself does not take much place. One frequent use-case for anonymous functions is within the *apply family of Base functions. Calculate the root mean squ...
TRUNCATE tableName; This will delete all the data and reset AUTO_INCREMENT index. It's much faster than DELETE FROM tableName on a huge dataset. It can be very useful during development/testing. When you truncate a table SQL server doesn't delete the data, it drops the table and recreates it, th...
Blocks are chunks of code enclosed between braces {} (usually for single-line blocks) or do..end (used for multi-line blocks). 5.times { puts "Hello world" } # recommended style for single line blocks 5.times do print "Hello " puts "world" end # recomme...
With a column of one of the string types, named my_date_field with a value such as [the string] 07/25/2016, the following statement demonstrates the use of the STR_TO_DATE function: SELECT STR_TO_DATE(my_date_field, '%m/%d/%Y') FROM my_table; You could use this function as part of WHERE clause a...
The switch structure performs the same function as a series of if statements, but can do the job in fewer lines of code. The value to be tested, as defined in the switch statement, is compared for equality with the values in each of the case statements until a match is found and the code in that blo...
Objective c: //this is the dictionary you start with. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"name1", @"Sam",@"name2", @"Sanju",nil]; //check if the dictionary contains the key you are going to modify. In this example, @&qu...
The following will echo each line in the file C:\scripts\testFile.txt. Blank lines will not be processed. for /F "tokens=*" %%A in (C:\scripts\testFile.txt) do ( echo %%A rem do other stuff here ) More advanced example shows, how derived in FOR loop from a restricted files set...
wildcard characters are used with the SQL LIKE operator. SQL wildcards are used to search for data within a table. Wildcards in SQL are:%, _, [charlist], [^charlist] % - A substitute for zero or more characters Eg: //selects all customers with a City starting with "Lo" SEL...
Simple one-liners may be specified as command line arguments to perl using the -e switch (think "execute"): perl -e'print "Hello, World!\n"' Due to Windows quoting rules you can't use single-quoted strings but have to use one of these variants: perl -e"print qq(Hello, W...
perl -ne'print if /foo/' file.txt Case-insensitive: perl -ne'print if /foo/i' file.txt
perl -pe"s/foo/bar/g" file.txt Or in-place: perl -i -pe's/foo/bar/g' file.txt On Windows: perl -i.bak -pe"s/foo/bar/g" file.txt
perl -lane'print "$F[0] $F[-1]"' data.txt # prints the first and the last fields of a space delimited record CSV example: perl -F, -lane'print "$F[0] $F[-1]"' data.csv
Without a backup copy (not supported on Windows) perl -i -pe's/foo/bar/g' file.txt With a backup copy file.txt.bak perl -i.bak -pe's/foo/bar/g' file.txt With a backup copy old_file.txt.orig in the backup subdirectory (provided the latter exists): perl -i'backup/old_*.orig' -pe's/foo/bar/g' ...
With XML::Rabbit it is possible to consume XML files easily. You define in a declarative way and with an XPath syntax what you are looking for in the XML and XML::Rabbit will return objects according to the given definition. Definition: package Bookstore; use XML::Rabbit::Root; has_xpath_object_...
It is good practice to test the calling program's __name__ variable before executing your code. import sys def main(): # Your code starts here # Don't forget to provide a return code return 0 if __name__ == "__main__": sys.exit(main()) Using this pattern ens...
Adding components one after another results in a UI that's hard to use, because the components all are somewhere. The components are ordered from top to bottom, each component in a separate "row". To remedy this and provide you as developer with a possibility to layout components easily S...
One of the easiest ways to deploy Grails 3.x is to build an executable jar file that embeds a servlet container (Tomcat, Undertow, etc) with the application. Modify build.gradle: // Remove or comment out the war plugin: // apply plugin:"war" // Enable the executable jar: springBoot ...
genRandom creates a stream of random numbers that has a one in four chance of terminating each time it's called. def genRandom: Stream[String] = { val random = scala.util.Random.nextFloat() println(s"Random value is: $random") if (random < 0.25) { Stream.empty[String] ...
curl -XGET 'http://www.example.com:9200/myIndexName/_count?pretty' Output: { "count" : 90, "_shards" : { "total" : 6, "successful" : 6, "failed" : 0 } } The index has 90 documents within it. Reference Link: Here
curl -XGET 'http://www.example.com:9200/myIndexName/myTypeName/1' Output: { "_index" : "myIndexName", "_type" : "myTypeName", "_id" : "1", "_version" : 1, "found": true, "_source&qu...

Page 304 of 826