Tutorial by Examples: dc

An alternative to extending Enumeration is using sealed case objects: sealed trait WeekDay object WeekDay { case object Mon extends WeekDay case object Tue extends WeekDay case object Wed extends WeekDay case object Thu extends WeekDay case object Fri extends WeekDay case objec...
<?php namespace models; use yii\db\ActiveRecord; use yii\behaviors\TimestampBehavior; class Post extends ActiveRecord { public static function tableName() { return 'post'; } public function rules() { ...
The fetch function does not send cookies by default. There are two possible ways to send cookies: Only send cookies if the URL is on the same origin as the calling script. fetch('/login', { credentials: 'same-origin' }) Always send cookies, even for cross-origin calls. fetch('htt...
As Handlers are used to send Messages and Runnables to a Thread's message queue it's easy to implement event based communication between multiple Threads. Every Thread that has a Looper is able to receive and process messages. A HandlerThread is a Thread that implements such a Looper, for example th...
If you want to check that a string contains only a certain set of characters, in this case a-z, A-Z and 0-9, you can do so like this, import re def is_allowed(string): characherRegex = re.compile(r'[^a-zA-Z0-9.]') string = characherRegex.search(string) return not bool(string) ...
Grand Central Dispatch works on the concept of "Dispatch Queues". A dispatch queue executes tasks you designate in the order which they are passed. There are three types of dispatch queues: Serial Dispatch Queues (aka private dispatch queues) execute one task at a time, in order. They a...
3.0 To run tasks on a dispatch queue, use the sync, async, and after methods. To dispatch a task to a queue asynchronously: let queue = DispatchQueue(label: "myQueueName") queue.async { //do something DispatchQueue.main.async { //this will be called in main t...
A common question is how to juxtapose (combine) physically separate geographical regions on the same map, such as in the case of a choropleth describing all 50 American states (The mainland with Alaska and Hawaii juxtaposed). Creating an attractive 50 state map is simple when leveraging Google Maps...
In this example we aim to accomplish one of the most common tasks: I have a small DC motor laying around, how do I use my Arduino to control it? Easy, with PWM and serial communication, using the function analogWrite() and the Serial library. The basics Pulse Width Modulation or PWM for short is a...
Say you have a <textarea> and you want to retrieve info about the number of: Characters (total) Characters (no spaces) Words Lines function wordCount( val ){ var wom = val.match(/\S+/g); return { charactersNoSpaces : val.replace(/\s+/g, '').length, characte...
Stored procedures can be created through a database management GUI (SQL Server example), or through a SQL statement as follows: -- Define a name and parameters CREATE PROCEDURE Northwind.getEmployee @LastName nvarchar(50), @FirstName nvarchar(50) AS -- Define the query to be...
Broadcast variables are read only shared objects which can be created with SparkContext.broadcast method: val broadcastVariable = sc.broadcast(Array(1, 2, 3)) and read using value method: val someRDD = sc.parallelize(Array(1, 2, 3, 4)) someRDD.map( i => broadcastVariable.value.apply(...
The following code will print the arguments to the program, and the code will attempt to convert each argument into a number (to a long): #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <limits.h> int main(int argc, char* argv[]) { for (int ...
Defining a member block inside a resource creates a route that can act on an individual member of that resource-based route: resources :posts do member do get 'preview' end end This generates the following member route: get '/posts/:id/preview', to: 'posts#preview' # preview_post_p...
child.py import time def main(): print "starting work" time.sleep(1) print "work work work work work" time.sleep(1) print "done working" if __name__ == '__main__': main() parent.py import os def main(): for i in range(5):...
This example starts Notepad, waits for it to be closed, then gets its exit code. #include <Windows.h> int main() { STARTUPINFOW si = { 0 }; si.cb = sizeof(si); PROCESS_INFORMATION pi = { 0 }; // Create the child process BOOL success = CreateProcessW( L"C:...
When adding indented code blocks inside a list you first need a blank line, then to indent the code further. Different flavours of Markdown have different rules for this. StackExchange requires code to be indented by 8 characters instead of the usual 4. (Spaces replaced with * for clarity): 1...
ansible -i hosts -m ping targethost -i hosts defines the path to inventory file targethost is the name of the host in the hosts file
Inline style You can manipulate the inline CSS style of an HTML element by simply reading or editing its style property. Assume the following element: <div id="element_id" style="color:blue;width:200px;">abc</div> With this JavaScript applied: var element = doc...
To display the hunks that are staged for commit: git diff --cached

Page 5 of 28