Skip to content

Instantly share code, notes, and snippets.

@finalfantasia
finalfantasia / javascript_scoping_and_hoisting.js
Last active August 29, 2015 14:03
JavaScript Scoping and Hoisting
// related write-up
// http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
// example code
var a = 1;
function b (arguments) {
var a = 3;
@finalfantasia
finalfantasia / fun_with_javascript_prototypes.js
Last active August 29, 2015 14:06
Fun with JavaScript Prototypes
// Fun
Object instanceof Function // true
Function instanceof Object // true
// Types of various prototype objects:
typeof Object.prototype === 'object' // true
typeof Boolean.prototype === 'object' // true
typeof Number.prototype === 'object' // true
@finalfantasia
finalfantasia / calculating_the_specificity_of_a_css_selector.md
Last active August 29, 2015 14:08
Calculating a CSS Selector's Specificity

A selector's specificity is represented by concatenating three numbers: a-b-c (in a number system with a large base), which are calculated as follows:

a = the count of ID selectors in the selector
b = the count of class selectors, attributes selectors, and pseudo-classes in the selector
c = the count of type selectors and pseudo-elements in the selector
ignore the universal selector 

Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.

Examples:

@finalfantasia
finalfantasia / test_double.md
Last active August 29, 2015 14:08
Test Double

Meszaros uses the term Test Double as the generic term for any kind of pretend object used in place of a real object for testing purposes. The name comes from the notion of a Stunt Double in movies. (One of his aims was to avoid using any name that was already widely used.) Meszaros then defined four particular kinds of double:

  • Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
  • Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
  • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'.
  • Mocks are what we are talking about here: objects pre-programmed with expectations whi
@finalfantasia
finalfantasia / using_base16_256_color_themes_in_vim_in_gnome_terminal.md
Last active August 29, 2015 14:10
Using Base16 256-color themes in Vim in GNOME Terminal
@finalfantasia
finalfantasia / spaces.md
Last active August 29, 2015 14:12
Spaces

White space contributes as much to the effect produced by software text as silence to the effect of a musical piece.

The general rule, for simplicity and ease of remembering, is to follow as closely as possible the practice of a standard written language. By default, we will assume this language to be English, although it may be appropriate to adapt the conventions to the slightly different rules of other languages.

Here are some of the consequences. You will use a space:

  • Before an opening parenthesis, but not after: f (x) (not f(x), the C style, or f( x)).
  • After a closing parenthesis unless the next character is a punctuation sign such as a period or semicolon; but not before. Hence: proc1 (x); x := f1 (x) + f2 (y).
  • After a comma but not before: g (x, y, z).
  • After the two dash signs that start a comment: -- A comment.
@finalfantasia
finalfantasia / clean_and_stop_creation_of_wdmc_directories_on_wd_my_cloud_ex2.md
Last active September 14, 2015 07:55
Clean and Stop Creation of .wdmc Directories on WD My Cloud EX2
  1. Stop the daemons:
    /etc/init.d/wdmcserverd stop
    /etc/init.d/wdphotodbmergerd stop
  1. Disable the daemons:
    update-rc.d wdphotodbmergerd disable
    update-rc.d wdmcserverd disable
@finalfantasia
finalfantasia / why_functional_programming_has_not_taken_over_yet.md
Created March 3, 2016 18:44
Why functional programming hasn't taken over yet

Because all those advantages are also disadvantages.

Stateless programs; No side effects

Real-world programs are all about side effects and mutation. When the user presses a button it's because they want something to happen. When they type in something, they want that state to replace whatever state used to be there. When Jane Smith in accounting gets married and changes her name to Jane Jones, the database backing the business process that prints her paycheque had better be all about handling that sort of mutation. When you fire the machine gun at the alien, most people do not mentally model that as the construction of a new alien with fewer hit points; they model that as a mutation of an existing alien's properties. When the programming language concepts fundamentally work against the domain being modelled, it's hard to justify using that language.

Concurrency; Plays extremely nice with the rising multi-core technology

The problem is just pushed around. With immutable data structures you have ch

@finalfantasia
finalfantasia / automatic_semicolon_insertion_in_javascript_everything_you_need_to_know.md
Last active November 4, 2016 17:31
Automatic Semicolon Insertion in JavaScript—Everything You Need to Know

#Automatic Semicolon Insertion in JavaScript—Everything You Need to Know Friday, May 28, 2010

Automatic semicolon insertion is one of JavaScript's most controversial syntactic features. There are also many misconceptions surrounding it.

Some JavaScript programmers use semicolons at the end of every statement and some use them only where strictly required. Most do something in between and a few even intentionally add extra semicolons as a matter of style.

Even if you use semicolons at the end of every statement, some constructs parse in non-obvious ways. Regardless of your preferences in semicolon usage, you must know the rules to write JavaScript professionally. If you remember a few simple rules, all of which are explained here, you will be able to understand how any program you might encounter will be parsed and will be an expert on JavaScript automatic semicolon insertion or ASI.

##Where Semicolons are Allowed

@finalfantasia
finalfantasia / react_redux_todo_app.js
Last active November 10, 2016 06:56
React-Redux Todo App
// <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.js"></script>
// <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.js"></script>
/*
<body>
<div id="root" />
</body>
*/
// redux api