Skip to content

Instantly share code, notes, and snippets.

@paulmillr
paulmillr / mongodb_sharding.sh
Created August 10, 2011 10:30
MongoDB sharding setup (quick & dirty)
#!/usr/bin/env zsh
# Change "Mongal" in text to name of your collection.
DATADIR="$HOME/Documents/data"
mkdir -p $DATADIR/db/{config,logs,0,1,2,3}
mkdir $DATADIR/backup
cd $DATADIR/db/logs
touch 0.log 1.log 2.log 3.log config.log main.log
chmod 666 *.log
@paulmillr
paulmillr / mapreduce.scala
Created March 10, 2012 16:03
Why functional programming matters (aka MapReduce for humans)
import com.cloudera.crunch._
import com.cloudera.scrunch._
class ScrunchWordCount {
def wordCount(inputFile: String, outputFile: String) = {
val pipeline = new Pipeline[ScrunchWordCount]
pipeline.read(from.textFile(inputFile))
.flatMap(_.toLowerCase.split("\\W+"))
.filter(!_.isEmpty())
.count
@paulmillr
paulmillr / replace-to-dashes.coffee
Created June 9, 2012 14:33
Add dashes to CoffeeScript source. toString ⇒ to-string. Issue #2370
fs = require 'fs'
# Usage: coffee replace-to-dashes.coffee src/**/*
replaceFile = (path) ->
fs.readFile path, (error, data) ->
return console.log error if error?
result = data
.toString()
.replace /([a-z])([A-Z])([a-z])/g, ($0, $1, $2, $3) ->
routes = require './routes'
# Execute handler on document ready event.
jQuery ->
# Initialise new Chaplin application.
# Specify controller suffix for clarity.
new Chaplin.Application
controllerSuffix: '-controller', pushState: false, routes: routes
@paulmillr
paulmillr / grunt.js
Last active April 26, 2016 14:31
Gulp / grunt
module.exports = function ( grunt ) {
/**
* Load required Grunt tasks. These are installed based on the versions listed
* in `package.json` when you do `npm install` in this directory.
*/
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
@paulmillr
paulmillr / Gruntfile.js
Created September 11, 2012 10:11
yeoman default config
module.exports = function( grunt ) {
'use strict';
//
// Grunt configuration:
//
// https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
//
grunt.initConfig({
// Project configuration
@paulmillr
paulmillr / method-missing.coffee
Created January 20, 2012 16:27
ECMAScript 6 proxies fun (method missing, negative array indexes)
# Ruby’s “method missing” analog with ES6 proxies.
proxify = (object) ->
new Proxy object, get: (receiver, name) ->
object[name] ? object.methodMissing.bind object, name
object = proxify
a: 1,
b: 15,
c: ->
'called'
@paulmillr
paulmillr / brunch-heroku-deploy.md
Last active March 29, 2019 23:12
Build & deploy brunch applications on Heroku.
  1. Add to .gitignore:

    node_modules
    public
    
  2. Add to your app dependencies of package.json:

@paulmillr
paulmillr / great_code.hs
Created May 4, 2012 15:17
Cool & pretty readable haskell code
data Cargo = Peasant
| Cabbage
| Wolf
| Goat
deriving (Eq, Enum, Show)
type ShoreState = [Cargo]
type Move = [Cargo]
type State = (ShoreState, ShoreState)
@paulmillr
paulmillr / less.less
Created March 9, 2012 08:26
Sass vs Stylus vs LESS
.border-radius (@radius) {
-webkit-border-radius: @radius;
-o-border-radius: @radius;
-moz-border-radius: @radius;
-ms-border-radius: @radius;
border-radius: @radius;
}
.user-list {
// need to use special `.` syntax