Skip to content

Instantly share code, notes, and snippets.

View joyrexus's full-sized avatar

J. Voigt joyrexus

View GitHub Profile
@joyrexus
joyrexus / mint.coffee.md
Last active December 15, 2015 05:19
Minimalist templating

Mint

Minimalist templating.

fs = require 'fs'
coffee = require 'coffee-script'

The render method returns a template from template text or an interpolated template if passed a data object. Ex:

@joyrexus
joyrexus / factory.coffee.md
Last active December 15, 2015 07:19
Little factory example.

Factory Pattern

Trevor Burnham's example.

class Enterprise 
constructor: (@captain) ->
 @name = @constructor.name
@joyrexus
joyrexus / product.coffee
Last active December 15, 2015 11:09
Cartesian product.
{test, ok, arrayEq} = require 'testy'
Array::uniq = ->
U = {}
U[@[i]] = @[i] for i in [0...@length]
v for k, v of U
flatten = (arr) -> arr.reduce ((x, y) -> x.concat y), []
@joyrexus
joyrexus / calling.coffee.md
Last active December 15, 2015 11:09
Little hack for callable classes.

Callable Classes

A quick little hack to make a class callable.

Note that this is generally inadvisable and can be avoided altogether by assigning the target class method to a function.

Hack

@joyrexus
joyrexus / rename.md
Last active December 15, 2015 14:08
Rename files w/ regexes.

Rename

Rename files with regular expressions. A filename fixer utility courtesy of Larry Wall.

Usage

rename expr [files]

Examples

@joyrexus
joyrexus / head_test.md
Last active December 15, 2015 17:09
Move files with pattern in first line to target dir

Header Testing

List files containing PATTERN in first line of a file:

perl -ne'print "$ARGV\n" if /PATTERN/; close ARGV' *.txt

List files not containing PATTERN in first line of a file:

perl -ne'print "$ARGV\n" unless /PATTERN/; close ARGV' *.txt

@joyrexus
joyrexus / zebra.md
Last active March 3, 2017 21:01
Norvig's treatment of the zebra puzzle.
@joyrexus
joyrexus / package.py
Created April 4, 2013 21:01
Relative imports for non-package files.
import sys
sys.path.insert(0, '..') # relative path to MODULE, change as appropriate
from MODULE import * # replace MODULE with the name of your module
@joyrexus
joyrexus / xhr.coffee.md
Created April 5, 2013 15:57
XHR posting example.
@joyrexus
joyrexus / README.md
Last active December 15, 2015 20:58
Move files with specified pattern in first line to target dir.

Sift files by header

Suppose you have a set of files you want to partition on the basis of the first line in the file.

This script enables you to move a filtered subset (based on the header line) to a target directory.

You specify the pattern in the first line of the files you wish to move. Those files containing the pattern in their header get moved, those without don't.