Skip to content

Instantly share code, notes, and snippets.

@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 / js-functions.md
Last active September 17, 2022 04:24
JS Functions

Functions

Functions are first–class citizens in JS, meaning that they can be passed around like any other type of data, eg, variables. http://en.wikipedia.org/wiki/First-class_function

Declared function

Declared functions build in memory immediately when the program loads.

Basic syntax

@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 / js-objects.md
Last active October 10, 2019 21:03
JS Objects

Objects

Object properties can refer to numbers, strings, arrays, functions, and other objects. Properties will also accept variables.

Creating objects

Literal notation - "Object Literal"

Literal objects can have properties and methods added to them on the fly, which we cannot do with a constructor. To add a method to a constructor we must extend its prototype chain.

@nifl
nifl / ghostinstall.md
Last active January 2, 2016 15:39
INSTALLING GHOST ON UBUNTU AND EC2 adapted from http://aexmachina.info/installing-ghost-on-ubuntu-and-aws-ec2/

PREREQUISITES

  • Node.js
  • Ruby
  • Bundler

GET GHOST

This one's pretty simple, just change directory to somewhere sensible and run the following commands:

dirName="my-blog"
@nifl
nifl / apache-tomcat-railo-multiweb.md
Last active December 27, 2015 14:59
Updated instructions on setting up multiple web instances of Railo 4 with Tomcat 7.0.42 and Apache on Mac OS 10.9. The original instructions appeared on Sean Corfields blog http://corfield.org/entry/Railo_on_Tomcat__multiweb and http://corfield.org/entry/Railo_for_Dummies_Part_IV_Appendix. Also credit to Jamie Krug for his updated post on proxyi…

Tomcat

In the Tomcat folder create a railo/ folder and copy in the contents of the unzipped Railo JARs ZIP file (or from the WEB-INF/lib/ folder of the unzipped Railo WAR file). In the Tomcat conf/ folder, edit catalina.properties and find the common.loader class path. We're going to add the Railo JARs to the common class path so that every web application can have Railo CFML pages. The new common.loader definition should look like this (all on one line, no spaces): common.loader=${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/railo,${catalina.home}/railo/*.jar

Note: embedding Railo directly in Tomcat like this means that you will end up with a generated WEB-INF/ folder in each webroot, containing some Railo files (about 2MB).

Unless you're going to use the default web applications that come with Tomcat, this is a good time to empty the Tomcat webapps/ folder. You could create a default/ folder in the Tomcat folder and move everything from webapps/ to default/

vid.addEventListener('error', function(evt) {
logEvent(evt,'red');
}, false);
...
function logEvent(evt, color) {
switch (evt.type) {
...
case 'error':
var error = document.querySelector('video').error;
switch (error.code) {
@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...

<!---
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 / 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