Tutorial by Examples

#![feature(start, libc, lang_items)] #![no_std] #![no_main] // The libc crate allows importing functions from C. extern crate libc; // A list of C functions that are being imported extern { pub fn printf(format: *const u8, ...) -> i32; } #[no_mangle] // The main function, with...
From guides.rubyonrails.org: Instead of generating a model directly . . . let's set up a scaffold. A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above. Here's a...
To separate a URL into its individual components, use parse_url(): $url = 'http://www.example.com/page?foo=1&bar=baz#anchor'; $parts = parse_url($url); After executing the above, the contents of $parts would be: Array ( [scheme] => http [host] => www.example.com [path...
The StringBuffer, StringBuilder, Formatter and StringJoiner classes are Java SE utility classes that are primarily used for assembling strings from other information: The StringBuffer class has been present since Java 1.0, and provides a variety of methods for building and modifying a "buf...
git config --global merge.conflictstyle diff3 Sets the diff3 style as default: instead of the usual format in conflicted sections, showing the two files: <<<<<<< HEAD left ======= right >>>>>>> master it will include an additional section containi...
Rails files - and Ruby files in general - should be named with lower_snake_case filenames. E.g. app/controllers/application_controller.rb is the file that contains the ApplicationController class definition. Note that while PascalCase is used for class and module names, the files in which they r...
The following query returns the database options and metadata: select * from sys.databases WHERE name = 'MyDatabaseName';
parseFloat accepts a string as an argument which it converts to a float/ parseFloat("10.01") // = 10.01
// Generic types are declared using the <T> annotation struct GenericType<T> { pub item: T } enum QualityChecked<T> { Excellent(T), Good(T), // enum fields can be generics too Mediocre { product: T } }
// explicit type declaration let some_value: Option<u32> = Some(13); // implicit type declaration let some_other_value = Some(66);
Generics types can have more than one type parameters, eg. Result is defined like this: pub enum Result<T, E> { Ok(T), Err(E), }
// Only accept T and U generic types that also implement Debug fn print_objects<T: Debug, U: Debug>(a: T, b: U) { println!("A: {:?} B: {:?}", a, b); } print_objects(13, 44); // or annotated explicitly print_objects::<usize, u16>(13, 44); The bounds must cover a...
Generic functions allow some or all of their arguments to be parameterised. fn convert_values<T, U>(input_value: T) -> Result<U, String> { // Try and convert the value. // Actual code will require bounds on the types T, U to be able to do something with them. } If the compi...
PowerShell, unlike some other scripting languages, sends objects through the pipeline. What this means is that when you send data from one command to another, it's essential to be able to create, modify, and collect objects. Creating an object is simple. Most objects you create will be custom obj...
You can use curly braces to interpolate expressions into string literals: def f(x: String) = x + x val a = "A" s"${a}" // "A" s"${f(a)}" // "AA" Without the braces, scala would only interpolate the identifier after the $ (in this case f...
Git is pretty good at identifying binary files, but you can explicitly specify which files are binary. Create a .gitattributes file in the project root containing: *.png binary binary is a built-in macro attribute equivalent to -diff -merge -text.
Generally, sets are a type of collection which stores unique values. Uniqueness is determined by the equals() and hashCode() methods. Sorting is determined by the type of set. HashSet - Random Sorting Java SE 7 Set<String> set = new HashSet<> (); set.add("Banana"); set.ad...
Description When working with a team who uses different operating systems (OS) across the project, sometimes you may run into trouble when dealing with line endings. Microsoft Windows When working on Microsoft Windows operating system (OS), the line endings are normally of form - carriage return ...
Each time WordPress loads the page, it will run main loop. The loop is the way to iterate over all elements related to the page you are currently on. Main loop will work on a global WP_Query object. The query has a globalized method have_posts(), that allows us to loop through all results. Finally...
You can also use loop with curly brackets like this: if ( have_posts() ) { while ( have_posts() ) { the_post(); var_dump( $post ); } }

Page 221 of 1336