Skip to content

Instantly share code, notes, and snippets.

# db/migrate/20120625030355_add_deleted_at_to_user.rb
class AddDeletedAtToUser < ActiveRecord::Migration
def change
add_column :users, :deleted_at, :datetime
end
end
@tjcelaya
tjcelaya / gist:4e0c7a6a5a0b0b771fba
Last active August 29, 2015 14:11
Manually Serialize a Simple Form
document.addEventListener('DOMContentLoaded', function() {
var formEl = document.querySelector('#the-form'),
serializeForm = function(el) {
var formData = {};
for (var i = 0, l = el.length; i < l; i++) {
var currentEl = el[i];
switch (currentEl.type) {
@tjcelaya
tjcelaya / gulpfile.js
Last active August 29, 2015 14:17
Super-simple Gulp task for Browserify (no fancy super-efficient watch here)
'use strict';
var gulp = require('gulp'),
browserify = require('browserify'),
livereload = require('gulp-livereload'),
source = require('vinyl-source-stream');
gulp.task('browserify', function () {
return browserify('./js/src/app.js')
.bundle()
@tjcelaya
tjcelaya / recent-edits.sh
Last active August 29, 2015 14:18
git status summary + modification time (sorted)
#!/bin/bash
git status --porcelain | awk '{print $2}' | xargs stat -f '%m %Sm %N' | sort | cut -d ' ' -f 2-
(function () {
//
// Global ajax loaders
//
// This is useful for showing a loading animation, yet still taking
// advantage of the default behavior of m.request, which is to wait
// for all requests to complete before rendering the view.
//
// The loader is assumed to already be on the page
var loader = document.querySelector('.ajax-loader')
@tjcelaya
tjcelaya / gist:d9c71e8bfe1bb177effb
Last active January 23, 2016 08:41
lodash-fp list of objects self-join
////
// WARNING: THE FOLLOWING IS ONLY A TEST OF THE EMERGENCY IN-MEMORY ORM
// NO CLAIMS ARE MADE AS TO THE PRACTICALITY OR WEB-SCALE-NESS OF PERFORMING CLIENT-SIDE JOINS
////
let l = require('lodash-fp')
l.mixin({ id: l.identity })
l.mixin({ prop: l.property })
function leven(a, b){if(a.length == 0) return b.length; if(b.length == 0) return a.length; var matrix = []; /* increment along the first column of each row */ var i; for(i = 0; i <= b.length; i++){matrix[i] = [i]; } /* increment each column in the first row */ var j; for(j = 0; j <= a.length; j++){matrix[0][j] = j; } /* Fill in the rest of the matrix */ for(i = 1; i <= b.length; i++){for(j = 1; j <= a.length; j++){if(b.charAt(i-1) == a.charAt(j-1)){matrix[i][j] = matrix[i-1][j-1]; } else {matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, /* substitution */ Math.min(matrix[i][j-1] + 1, /* insertion */ matrix[i-1][j] + 1)); /* deletion */ } } } return matrix[b.length][a.length]; }
function cross(l1, l2, fn) { return l1.map(function (v1) { return l2.map(function (v2) { return fn(v1, v2); }) }) }
function zip(l1, l2) { var shorter = l1.length < l2.length ? l1 : l2; return shorter.map(function (v, k) { return [l1[k], l2[k]] }) }
function minIdx(l) { return l.indexOf(Math.min.apply(null, l)) }
/* throw away the "ta
function leven(a, b){if(a.length == 0) return b.length; if(b.length == 0) return a.length; var matrix = []; /* increment along the first column of each row */ var i; for(i = 0; i <= b.length; i++){matrix[i] = [i]; } /* increment each column in the first row */ var j; for(j = 0; j <= a.length; j++){matrix[0][j] = j; } /* Fill in the rest of the matrix */ for(i = 1; i <= b.length; i++){for(j = 1; j <= a.length; j++){if(b.charAt(i-1) == a.charAt(j-1)){matrix[i][j] = matrix[i-1][j-1]; } else {matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, /* substitution */ Math.min(matrix[i][j-1] + 1, /* insertion */ matrix[i-1][j] + 1)); /* deletion */ } } } return matrix[b.length][a.length]; }
function cross(l1, l2, fn) { return l1.map(function (v1) { return l2.map(function (v2) { return fn(v1, v2); }) }) }
function zip(l1, l2) { var shorter = l1.length < l2.length ? l1 : l2; return shorter.map(function (v, k) { return [l1[k], l2[k]] }) }
function minIdx(l) { return l.indexOf(Math.min.apply(null, l)) }
/* throw away the "ta
@tjcelaya
tjcelaya / id_rsa.pub
Created March 11, 2016 17:13
stitch public key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPMxmaFX8xc6267CK8n5IxDZLYFMB6ADEUEb0wHudlhKB95CTYCt7DGxyIHNCjAdBr5WEPs45jFW9FKNE6fM/QSByH6NXfTbdGQj9Z/Kl+VDtAfiNXuGxU8gAX3p5MQpHQdeTg4ntLdL7UvPnndy4zTeBEsWFEBtbVbaH3r+Of/YdAXbhwCVwzWSVr2Ht6wD8MRnpkC+gWPMsCuO4Cb7xxLy4UnBzUl9j/1Z1DVV3mhPQ1Oz0xw4tFu88V8hMf5EhprrwN87jTck6XZHcjWa/aNHFi42TSQI5orL4VXPqCxQ7gLtm9Zl1a+odUHbH2Evyw2zmJV+2nfwmEKxqy7dvJ tomas@Tomass-MBP.sf.stch.co
@tjcelaya
tjcelaya / makefile
Created April 9, 2017 03:56
makefile list
.PHONY: list
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null |\
awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' |\
sort |\
egrep -v -e '^[^[:alnum:]]' -e '^$@$$' |\
xargs