Skip to content

Instantly share code, notes, and snippets.

@nifl
nifl / js_notes.md
Last active September 26, 2015 20:57
JavaScript Notes

Javascript notes

JS is ...

  • Interpreted, not compiled
  • Case-sensitve
  • Whitespace insensitive except within quotes

Placement

@nifl
nifl / grok_vi.mdown
Created August 29, 2011 17:23
Your problem with Vim is that you don't grok vi.

Answer by Jim Dennis on Stack Overflow question http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

@nifl
nifl / ruby_notes.mdown
Created August 30, 2011 18:38
Ruby notes

Notes on the Ruby programming language

Documentation

Ruby Docs

Local docs using BASH

ri upcase # documents for upcase method
@nifl
nifl / sieve.js
Created October 26, 2012 22:43
Sieve Of Eratosthenes
function sieve(max) {
var D = [], primes = [];
for (var q=2; q<max; q++) {
if (D[q]) {
for (var i=0; i<D[q].length; i++) {
var p = D[q][i];
if (D[p+q]) D[p+q].push(p);
else D[p+q]=[p];
}
delete D[q];
@nifl
nifl / database.yml
Created October 30, 2012 23:52
Database.yml example using defaults for test, production, and cucumber
development: &defaults
adapter: postgresql
encoding: utf8
database: surveys_development
pool: 5
username: john
password: appleseed
test: &test
<<: *defaults
@nifl
nifl / fizzbuzz.js
Created November 2, 2012 04:17
FizzBuzz
for (i = 1; i <= 20; i++) {
if (i % 3 === 0) {
if (i % 5 === 0) {
console.log("FizzBuzz");
} else {
console.log("Fizz");
}
} else if (i % 5 === 0) {
console.log("Buzz");
} else {
@nifl
nifl / qbAPI.cfc
Created November 19, 2012 16:26
Quickbase REST API calls
<!---
Name: qbAPI.cfc
Author: Gernot Bartels
Description: Methods to interact with QuickBase
History: Migrated from CF8 to Railo 2010-04-02.
Created: 2009-03-25
Updated: 2010-04-02
--->
<cfcomponent output="false">
<!--- Login --->
@nifl
nifl / record.cfm
Created November 19, 2012 18:35
Queries QB for record object. If record ID exists, update; Otherwise create new record.
<!---
Name: record.cfm
Author: Gernot Bartels
Description: Queries QB for record object.
If record ID exists, update;
Otherwise create new record.
History: Created
Added logic
Usage: Surveys, Intake,
Created: 2011-08-05
<!---
Name: intake_xml.cfm
Author: Gernot Bartels
Description: Intake Application cfsavecontent object
Returns new record or update data.
History: Created
Usage: Surveys, Intake,
Created: 2012-09-05
Updated: 2012-10-15
--->
@nifl
nifl / check_object_instance.md
Created November 26, 2012 20:17
It is NOT 'bad' to use the new keyword. But if you forget it, you will be calling the object constructor as a regular function. If your constructor doesn't check its execution context then it won't notice that 'this' points to different object (ordinarily

And yes, new has one crucial disadvantage, ably described by other answers: if you forget to use it, your code will break without warning. Fortunately, that disadvantage is easily mitigated - simply add a bit of code to the function itself:

function foo()
{
   // if user accidentally omits the new keyword, this will 
   // silently correct the problem...
   if ( !(this instanceof foo) )
      return new foo();

// constructor logic follows...