Tutorial by Examples

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...
The minification is used to reduce the size of CSS and Javascript files to speed up download times. This process is done by removing all of the unnecessary white-space, comments, and any other non-essential content from the files. This process is done automatically when using a ScriptBundle or a St...
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...
We're defining a robust version of a function that reads the HTML code from a given URL. Robust in the sense that we want it to handle situations where something either goes wrong (error) or not quite the way we planned it to (warning). The umbrella term for errors and warnings is condition Functio...
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...
Cython is an alternative python interpreter. It uses the GIL, but lets you disable it. See their documentation As an example, using the code that David Beazley first used to show the dangers of threads against the GIL, we'll rewrite it using nogil: David Beazley's code that showed GIL threading ...
;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 (...
By running the command stack install Stack will copy a executable file to the folder /Users/<yourusername>/.local/bin/

Page 545 of 1336