Tutorial by Examples: sin

Suppose you have a pojo class Person public class Person { public String name; public Person(String name) { this.name = name; } } And you want to parse it into a JSON array or a map of Person objects. Due to type erasure you cannot construct classes of List<Person&g...
This example draws text paragraphs into any portions of the canvas that have opaque pixels. It works by finding the next block of opaque pixels that is large enough to contain the next specified word and filling that block with the specified word. The opaque pixels can come from any source: Path d...
C99 C99 introduced the concept of designated initializers. These allow you to specify which elements of an array, structure or union are to be initialized by the values following. Designated initializers for array elements For a simple type like plain int: int array[] = { [4] = 29, [5] = 31, [1...
Calculating the factorial of a number is a classic example of a recursive function. Missing the Base Condition: #include <stdio.h> int factorial(int n) { return n * factorial(n - 1); } int main() { printf("Factorial %d = %d\n", 3, factorial(3)); return 0;...
Show curl version: curl --version GET a remote resource and have it displayed in the terminal: curl http://stackoverflow.com GET a remote resource and save it in a local file: curl -o file https://stackoverflow.com Add headers to response: curl -i http://stackoverflow.com Output only...
Hi everyone! This is a demo I love running for people that get started with BigQuery. So let's run some simple queries to get you started. Setup You will need a Google Cloud project: Go to http://bigquery.cloud.google.com/. If it tells you to create a project, follow the link to create a proje...
This is a mistake that causes real confusion for Java beginners, at least the first time that they do it. Instead of writing this: if (feeling == HAPPY) System.out.println("Smile"); else System.out.println("Frown"); they accidentally write this: if (feeling == HAP...
const url = 'http://api.stackexchange.com/2.2/questions?site=stackoverflow&tagged=javascript'; const questionList = document.createElement('ul'); document.body.appendChild(questionList); const responseData = fetch(url).then(response => response.json()); responseData.then(({item...
#include <stdio.h> #define SIZE (10) int main() { size_t i = 0; int *p = NULL; int a[SIZE]; /* Setting up the values to be i*i */ for(i = 0; i < SIZE; ++i) { a[i] = i * i; } /* Reading the values using pointers */ for(p =...
For booleans, SQLite uses integers 0 and 1: sqlite> SELECT 2 + 2 = 4; 1 sqlite> SELECT 'a' = 'b'; 0 sqlite> SELECT typeof('a' = 'b'); integer > CREATE TABLE Users ( Name, IsAdmin ); > INSERT INTO Users VALUES ('root', 1); > INSERT INTO Users VALUES ('john', 0); > S...
You define a keyword argument in a method by specifying the name in the method definition: def say(message: "Hello World") puts message end say # => "Hello World" say message: "Today is Monday" # => "Today is Monday" You can define multip...
You can define a method to accept an arbitrary number of keyword arguments using the double splat (**) operator: def say(**args) puts args end say foo: "1", bar: "2" # {:foo=>"1", :bar=>"2"} The arguments are captured in a Hash. You can manip...
Unlike a parallel for-loop (parfor), which takes the iterations of a loop and distributes them among multiple threads, a single program, multiple data (spmd) statement takes a series of commands and distributes them to all the threads, so that each thread performs the command and stores the results....
Using Alternatives Many Linux distributions use the alternatives command for switching between different versions of a command. You can use this for switching between different versions of Java installed on a machine. In a command shell, set $JDK to the pathname of a newly installed JDK; e.g....
To check if a key exists in a Map, use the .has() method: map.has(key); Example: const map = new Map([[1, 2], [3, 4]]); console.log(map.has(1)); // true console.log(map.has(2)); // false
EntityState.Added can be set in two fully equivalent ways: By setting the state of its entry in the context: context.Entry(entity).State = EntityState.Added; By adding it to a DbSet of the context: context.Entities.Add(entity); When calling SaveChanges, the entity will be inse...
Using requestAnimationFrame may on some systems update at more frames per second than the 60fps. 60fps is the default rate if the rendering can keep up. Some systems will run at 120fps maybe more. If you use the following method you should only use frame rates that are integer divisions of 60 so th...
First, let's see three different ways of extracting data from a file. string fileText = File.ReadAllText(file); string[] fileLines = File.ReadAllLines(file); byte[] fileBytes = File.ReadAllBytes(file); On the first line, we read all the data in the file as a string. On the second line, we r...
Iterating over connected serial ports using System.IO.Ports; string[] ports = SerialPort.GetPortNames(); for (int i = 0; i < ports.Length; i++) { Console.WriteLine(ports[i]); } Instantiating a System.IO.SerialPort object using System.IO.Ports; SerialPort port = new SerialPort(); ...
You can use built-in functions to run PHP processes as forks. This is the most simple way to achieve parallel work if you don't need your threads to talk to each other. This allows you to put time intensive tasks (like uploading a file to another server or sending an email) to another thread so you...

Page 88 of 161