Skip to content

Instantly share code, notes, and snippets.

@mduvall
mduvall / pin.js
Created May 16, 2013 17:06
An example of the Pinterest waterfall layout.
var generateRandomBoxes = function() {
var $doc = $(".container");
var $bareBox = $("<div class='box' style='position:absolute; border:1px solid black; width:50px;'></div>");
var maxHeight = 200;
var height,
$box;
for (var i = 0; i < 100; i++) {
height = Math.floor(Math.random() * maxHeight);
$box = $bareBox.clone().css('height', height + 'px')
@mduvall
mduvall / media_queries.css
Created April 12, 2013 06:41
Some example media queries.
@media screen {
body {
width: 75%;
}
}
@media print {
body {
width: 100%;
}
@mduvall
mduvall / gist:5045753
Last active December 14, 2015 06:49
Sublime thing for grunting on save
import sublime, sublime_plugin
import os
import tempfile
class HandlebarsOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
folder_name, file_name = os.path.split(view.file_name())
extension = file_name[-3:]
if extension == 'hbs':
view.window().run_command('exec', { 'cmd': 'export PATH=/usr/local/bin:$PATH; /usr/local/share/npm/bin/grunt', 'shell': True, 'quiet': True})
@mduvall
mduvall / exec.py
Created November 30, 2012 00:17
Modified execution environment for sbl
import sublime, sublime_plugin
import os, sys
import thread
import subprocess
import functools
import time
class ProcessListener(object):
def on_data(self, proc, data):
pass
@mduvall
mduvall / git_lg
Created June 19, 2012 23:01
Cute git pretty log printer
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@mduvall
mduvall / ksubsets.rb
Created June 5, 2012 05:43
k-subset generation example
def subsets(s, k)
max = 1 << s.length
allsubsets = []
(0..max).each do |i|
subset = []
ii = i
index = 0
while ii > 0
if ii & 1 > 0
subset << s[index]
@mduvall
mduvall / msv.txt
Created May 21, 2012 18:15
A list of popular metasyntatic variables
These are metasyntatic variables often used in computer programming, people seem to not know about this.
* Foo
* Bar
* Baz
* Qux
* Quux
This is to avoid future questions about: "what's a qux?", "who's actually named Foo Bar?", "Did you mean <some absurd correction>?"
@mduvall
mduvall / Actors.scala
Created May 14, 2012 21:22
Various examples for Scala discussion
import scala.actors._
import scala.actors.Actor._
case object Poke
case object Feed
class Kid() extends Actor {
def act() {
loop {
react {
case Poke => {
@mduvall
mduvall / idiom_scraper.rb
Created May 14, 2012 20:57
Scrape a bunch of idioms, or something.
def scrape_all_the_idioms
url = "http://www.learnenglishfeelgood.com/americanidioms/lefgidioms"
idioms = {}
("b".."z").each do |letter|
idioms[letter] = {}
doc = Nokogiri::HTML(open(url + "_" + letter + ".html"))
idiom_definition = 3
doc.css("#content .blue").each do |nodes|
definition = doc.xpath("//*[@id='content']/text()[#{idiom_definition}]")
idioms[nodes.content] = doc.xpath("//*[@id='content']/text()[#{idiom_definition}]").text.strip!
@mduvall
mduvall / diff_date.rb
Created April 26, 2012 23:20
Date difference thing for .zshrc
ruby -e "require 'date'; puts \"It's been #{(Date.today - Date.new(2012,01,16)).to_i} days since the beginning\!\""