Tutorial by Examples: by

var persons = new[] { new {Id = 1, Name = "Foo"}, new {Id = 2, Name = "Bar"}, new {Id = 3, Name = "Fizz"}, new {Id = 4, Name = "Buzz"} }; var personsSortedByName = persons.OrderBy(p => p.Name); Console.WriteLine(string.Join(&quo...
var persons = new[] { new {Id = 1, Name = "Foo"}, new {Id = 2, Name = "Bar"}, new {Id = 3, Name = "Fizz"}, new {Id = 4, Name = "Buzz"} }; var personsSortedByNameDescending = persons.OrderByDescending(p => p.Name); Console.WriteL...
var persons = new[] { new { Name="Fizz", Job="Developer"}, new { Name="Buzz", Job="Developer"}, new { Name="Foo", Job="Astronaut"}, new { Name="Bar", Job="Astronaut"}, }; var groupedByJob = person...
string helloWorld = "hello world, how is it going?"; string[] parts1 = helloWorld.Split(','); //parts1: ["hello world", " how is it going?"] string[] parts2 = helloWorld.Split(' '); //parts2: ["hello", "world,", "how", "is&qu...
using System.Linq.Expressions; // Manually build the expression tree for // the lambda expression num => num < 5. ParameterExpression numParam = Expression.Parameter(typeof(int), "num"); ConstantExpression five = Expression.Constant(5, typeof(int)); BinaryExpression numLessTh...
Java 7 introduced the very useful Files class Java SE 7 import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.Path; Path path = Paths.get("path/to/file"); try { byte[] data = Files.readAllBytes(path); } catch(IOException e) { e.printStackTrace();...
A Pattern can be compiled with flags, if the regex is used as a literal String, use inline modifiers: Pattern pattern = Pattern.compile("foo.", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); pattern.matcher("FOO\n").matches(); // Is true. /* Had the regex not been compiled case...
A byte is a 8-bit signed integer. It can store a minimum value of -27 (-128), and a maximum value of 27 - 1 (127) byte example = -36; byte myByte = 96; byte anotherByte = 7; byte addedBytes = (byte) (myByte + anotherByte); // 103 byte subtractedBytes = (byte) (myBytes - anotherByte); // 89 ...
Variables can be accessed via dynamic variable names. The name of a variable can be stored in another variable, allowing it to be accessed dynamically. Such variables are known as variable variables. To turn a variable into a variable variable, you put an extra $ put in front of your variable. $va...
Place this code in a file named HelloWorld.scala: object Hello { def main(args: Array[String]): Unit = { println("Hello World!") } } Live demo To compile it to bytecode that is executable by the JVM: $ scalac HelloWorld.scala To run it: $ scala Hello When the Scala...
This example assumes Ruby and Ruby on Rails have already been installed properly. If not, you can find how to do it here. Open up a command line or terminal. To generate a new rails application, use rails new command followed by the name of your application: $ rails new my_app If you want to c...
The simplest way to iterate over a file line-by-line: with open('myfile.txt', 'r') as fp: for line in fp: print(line) readline() allows for more granular control over line-by-line iteration. The example below is equivalent to the one above: with open('myfile.txt', 'r') as fp: ...
object HelloWorld extends App { println("Hello, world!") } Live demo By extending the App trait, you can avoid defining an explicit main method. The entire body of the HelloWorld object is treated as "the main method". 2.11.0 Delayed Initialization Per the official d...
A common pitfall is confusing the equality comparison operators is and ==. a == b compares the value of a and b. a is b will compare the identities of a and b. To illustrate: a = 'Python is fun!' b = 'Python is fun!' a == b # returns True a is b # returns False a = [1, 2, 3, 4, 5] b = a ...
This Ruby example uses Mechanize, a library to automate web interactions. client_id is an OAuth client_id. game is the game directory to list. require 'mechanize' master_agent = Mechanize.new client_id = "123" game = "Minecraft" url = "https://api.twitch.tv/kraken...
To find files/directories with a specific name, relative to pwd: $ find . -name "myFile.txt" ./myFile.txt To find files/directories with a specific extension, use a wildcard: $ find . -name "*.txt" ./myFile.txt ./myFile2.txt To find files/directories matching one of ma...
To find files, use the -type f flag $ find . -type f To find directories, use the -type d flag $ find . -type d To find block devices, use the -type b flag $ find /dev -type b To find symlinks, use the -type l flag $ find . -type l
If you specify the variable's name in the capture list, the lambda will capture it by value. This means that the generated closure type for the lambda stores a copy of the variable. This also requires that the variable's type be copy-constructible: int a = 0; [a]() { return a; // Ok, 'a' ...
On an ext filesystem, each file has a stored Access, Modification, and (Status) Change time associated with it - to view this information you can use stat myFile.txt; using flags within find, we can search for files that were modified within a certain time range. To find files that have been modifi...
To encode a string into a byte array, you can simply use the String#getBytes() method, with one of the standard character sets available on any Java runtime: byte[] bytes = "test".getBytes(StandardCharsets.UTF_8); and to decode: String testString = new String(bytes, StandardCharsets.U...

Page 1 of 23