Tutorial by Examples: e

Backbone models describe how data is stored using JavaScript objects. Each model is a hash of fields called attributes and the behaviour of the model including validation is described by options. A model of Todo item in a TodoApp would be var ToDo = Backbone.Model.extend({ defaults: { assi...
The easiest way to create a custom data type in Haskell is to use the data keyword: data Foo = Bar | Biz The name of the type is specified between data and =, and is called a type constructor. After = we specify all value constructors of our data type, delimited by the | sign. There is a rule in...
Value constructors are functions that return a value of a data type. Because of this, just like any other function, they can take one or more parameters: data Foo = Bar String Int | Biz String Let's check the type of the Bar value constructor. :t Bar prints Bar :: String -> Int -> Foo...
Type constructors can take one or more type parameters: data Foo a b = Bar a b | Biz a b Type parameters in Haskell must begin with a lowercase letter. Our custom data type is not a real type yet. In order to create values of our type, we must substitute all type parameters with actual types. Be...
Most JVMs have an option to set the maximum heap size e.g. -Xmx64m -Xmx8g In Java 1.0 to 1.2 you could use -mx64m and this is still available on some JVMs for backward compatibility (E.g. Oracle JVM). There are a few common misconceptions about this setting. It doesn't set the heap size...
A lot of Vim users find the Esc too hard to reach, and end up finding another mapping that's easy to reach from the home row. Note that Ctrl-[ may be equivalent to Esc on an English keyboard, and is much easier to reach. jk inoremap jk <ESC> This one is really easy to trigger; just smash...
IPv4 To match IPv4 address format, you need to check for numbers [0-9]{1,3} three times {3} separated by periods \. and ending with another number. ^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$ This regular expression is too simple - if you want to it to be accurate, you need to check that the numbers are be...
This is the normal HTML table structure <style> table { width: 100%; } </style> <table> <tr> <td> I'm a table </td> </tr> </table> You can do same implementation like this <style> .table-...
A Stopwatch instance can measure elapsed time over several intervals with the total elapsed time being all individual intervals added together. This gives a reliable method of measuring elapsed time between two or more events. Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); double d =...
Redux is very functional, so unit testing is very straightforward. Action creator: export function showSidebar () { return { type: 'SHOW_SIDEBAR' } } Action creators unit test: import expect from 'expect' import actions from './actions' import * as type from './constants' desc...
Strict mode does not allow you to use duplicate function parameter names. function foo(bar, bar) {} // No error. bar is set to the final argument when called "use strict"; function foo(bar, bar) {}; // SyntaxError: duplicate formal argument bar
The simple answer, when asking how to use threads in Python is: "Don't. Use processes, instead." The multiprocessing module lets you create processes with similar syntax to creating threads, but I prefer using their convenient Pool object. Using the code that David Beazley first used to...
;Sends the keystroke for the letter "a" every 3 seconds. #Persistent SetTimer, SendLetterA, 3000 return SendLetterA() { Send, a }
This is an example of something that would have been straight up impossible with labels. If you execute the same label multiple times at the same time and they rely on variables that are being defined within them, they very likely interfere and cause unexpected behavior. Here is how to do it with f...
Consider the following example: type Company struct { Name string Location string } Hide/Skip Certain Fields To export Revenue and Sales, but hide them from encoding/decoding, use json:"-" or rename the variable to begin with a lowercase letter. Note that this prevents ...
Pipe operators are used to pass parameters to a function in a simple and elegant way. It allows to eliminate intermediate values and make function calls easier to read. In F#, there are two pipe operators: Forward (|>): Passing parameters from left to right let print message = print...
When you are programming in OpenGL or any other graphics api you will hit a brick wall when you are not that good in math. Here I will explain with example code how you can achieve movement/scaling and many other cool stuff with your 3d object. Let's take a real life case... You've made a awesome (...
If we have this dictionary: set alpha {alice {items {}} bob {items {}} claudia {items {}} derek {items {}}} And want to add "fork" and "peanut" to Alice's items, this code won't work: dict lappend alpha alice items fork peanut dict get $alpha alice # => items {} items f...
There are two ways to register a background page in the extension manifest. The scripts property In the common case, a background page doesn't require any HTML markup. We can register these kinds of background pages using the scripts property. In this case, a background page will be generated...
The ref keyword is used to pass an Argument as Reference. out will do the same as ref but it does not require an assigned value by the caller prior to calling the function. Ref Parameter :-If you want to pass a variable as ref parameter then you need to initialize it before you pass it as ref param...

Page 482 of 1191