Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / scp_on_save.py
Last active December 19, 2015 12:59
Ghetto SCP on sublime using subprocess
import sublime, sublime_plugin
import os
import tempfile
import subprocess
class SCPOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
folder_name, file_name = os.path.split(view.file_name())
file_path = folder_name + '/' + file_name
command = 'scp ' + file_path + ' <URL HERE>:' + file_path + ' > /dev/null'
{ type: 'Program',
body:
[ { type: 'VariableDeclaration',
declarations:
[ { type: 'VariableDeclarator',
id: { type: 'Identifier', name: 'obj', range: [ 4, 7 ] },
init:
{ type: 'ObjectExpression',
properties:
[ { type: 'Property',
@mduvall
mduvall / consensus_string.go
Created March 30, 2014 05:48
Quick example of using FASTA file to compute consensus strings
package main
import (
"fasta"
"fmt"
)
func main() {
fastaFile := fasta.NewFastaFile("cons.txt")
@mduvall
mduvall / reading_frame.go
Created April 2, 2014 04:20
Get possible protein strings from reading frames in DNA
package main
import (
"fasta"
"fmt"
"strings"
)
func main() {
fastaFile := fasta.NewFastaFileWithPath("orf.txt")