Skip to content

Instantly share code, notes, and snippets.

View davidpdrsn's full-sized avatar

David Pedersen davidpdrsn

View GitHub Profile
@davidpdrsn
davidpdrsn / bootstrap.sh
Last active January 1, 2016 08:29
Bootstrap rails app
#!/bin/bash
rake db:migrate
git init
git add --all
git commit -m "generate rails app"
cat ~/dotfiles/Gemfile_template >> Gemfile
git add --all
git commit -m "add required testing gems"
rm -rf test
@davidpdrsn
davidpdrsn / backup
Created January 2, 2014 12:55
Super powered backups!
#!/usr/bin/env ruby
class TimeMachine
def initialize(dir)
@dir = dir
end
def start!
unless File.exists?("#{@dir}/.git")
init_backup!
@davidpdrsn
davidpdrsn / findDirs.js
Created April 13, 2014 10:48
Function for getting at dirs within a dir.
var fs = require("fs");
var addBasePath = function(path) {
if (/\/$/.test(path)) {
return function(dir) { return path + dir };
} else {
return function(dir) { return path + "/" + dir };
}
};
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
@davidpdrsn
davidpdrsn / gist:4daa814f35577f397cde
Created May 15, 2014 07:50
Capistrano deploy attempt
$ bundle exec cap deploy
triggering load callbacks
* 2014-05-15 09:49:58 executing `staging'
triggering start callbacks for `deploy'
* 2014-05-15 09:49:58 executing `multistage:ensure'
* 2014-05-15 09:49:58 executing `deploy'
* 2014-05-15 09:49:58 executing `deploy:update'
** transaction: start
* 2014-05-15 09:49:58 executing `deploy:update_code'
updating the cached checkout on all servers
@davidpdrsn
davidpdrsn / examples.coffee
Created June 1, 2014 17:37
Useful higher order functions in CoffeeScript
add = (x, y) -> x+y
squared = (x) -> x*x
console.log f.curry(add)(1)(2)
console.log f.curry(Array::map, [1,2,3])(squared)
f.flip(f.join)((-> console.log "hi"), (-> console.log "there"))()
@davidpdrsn
davidpdrsn / mergesort.swift
Last active August 24, 2016 13:11
Merge sort in Swift
import Foundation
// Build 100 random numbers between 0 and 100
var numbers = Int[]()
for i in 1..100 {
let n = Int(arc4random() % 101)
numbers.append(n)
}
func elementsInRange<T>(a: T[], start: Int, end: Int) -> (T[]) {
@davidpdrsn
davidpdrsn / gist:2c66184893fd550bd276
Created June 26, 2014 20:45
Quicksort and mergesort
mergesort = (->
merge = (x, y, acc = []) ->
if x.length == 0
acc.concat(y)
else if y.length == 0
acc.concat(x)
else if x[0] < y[0]
merge x[1..-1], y, acc.concat x[0]
else
merge x, y[1..-1], acc.concat y[0]
#pragma mark - validation
- (BOOL)validateForInsert:(NSError *__autoreleasing *)error {
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
[userInfo setObject:@"Cannot add more than 10 moves" forKey:NSLocalizedFailureReasonErrorKey];
[userInfo setObject:self forKey:NSValidationObjectErrorKey];
NSError *tooManyMovesError = [NSError errorWithDomain:@"TenMovesDomain" code:NSManagedObjectValidationError userInfo:userInfo];
if (*error == nil) {