Skip to content

Instantly share code, notes, and snippets.

View mark-rushakoff's full-sized avatar
🙈
I'm not watching GitHub notifications. Contact me directly to get my attention.

Mark Rushakoff mark-rushakoff

🙈
I'm not watching GitHub notifications. Contact me directly to get my attention.
View GitHub Profile
@mark-rushakoff
mark-rushakoff / gist:1515168
Created December 23, 2011 19:36
Underscore mixins for function binding helpers
// Run with jsFiddle at http://jsfiddle.net/MarkRushakoff/jQwGz/
_.mixin({
bindFiltered : function(object, filterFunc) {
var funcNames = _(object).chain().functions().filter(filterFunc).value();
var args = [object].concat(funcNames);
return _.bindAll.apply(_, args);
},
bindMatching : function(object, regex) {
@mark-rushakoff
mark-rushakoff / gist:1922091
Created February 27, 2012 07:01
Detect data leaks in jQuery
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.7.1");
function findLeaks(jQuery) {
var cache = {};
jQuery.each(jQuery.cache, function(key, val) {
@mark-rushakoff
mark-rushakoff / gist:1959568
Created March 2, 2012 16:44
Make jasmine run at full speed when in a background tab
var foregroundScreenRefreshRate = 1500;
var backgroundScreenRefreshRate = 9000;
jasmine.getEnv().updateInterval = foregroundScreenRefreshRate;
$(window).focus(function() {
jasmine.getEnv().updateInterval = foregroundScreenRefreshRate;
});
$(window).blur(function() {
@mark-rushakoff
mark-rushakoff / sample.js
Created March 2, 2012 21:10
Sample gist for try-jasmine
function add(a, b) {
return a + b;
}
@mark-rushakoff
mark-rushakoff / .vimrc
Created March 31, 2012 18:36
My .vimrc
syn on
set syn=auto
filetype on
filetype plugin on
filetype indent on
autocmd FileType haml set ts=2 shiftwidth=2
autocmd FileType ruby set ts=2 shiftwidth=2
autocmd FileType javascript set nocindent
@mark-rushakoff
mark-rushakoff / io_popen_example.rb
Last active December 13, 2015 20:48
How to simultaneously print and capture the output of an external command in Ruby
#!/usr/bin/env ruby
cmd = %q[echo '3...'; sleep 1;
echo '2...'; sleep 1;
echo '1...'; sleep 1;
echo 'Liftoff!']
puts '------ beginning command ------'
output_log = []
IO.popen(cmd).each do |line|
@mark-rushakoff
mark-rushakoff / bash_tar.sh
Last active December 14, 2015 02:49
Demonstration of how gzip seems to embed a timestamp
> echo 'Hello!' > hello.txt
> # Create 2 tarballs at right about the same time:
> tar czf hello1.tar.gz hello.txt; tar czf hello2.tar.gz hello.txt
> md5 * # The tarballs have the same md5
MD5 (hello.txt) = e134ced312b3511d88943d57ccd70c83
MD5 (hello1.tar.gz) = bfdacca1166009500d60151d73c4da7e
MD5 (hello2.tar.gz) = bfdacca1166009500d60151d73c4da7e
> tar czf hello1.tar.gz hello.txt; tar czf hello2.tar.gz hello.txt
> md5 * # The tarballs have a different md5
MD5 (hello.txt) = e134ced312b3511d88943d57ccd70c83
@mark-rushakoff
mark-rushakoff / find_rescue.sh
Created March 17, 2013 02:35
Finding number of particular statements in a git project
#!/usr/bin/sh
git grep -c rescue . | # or whatever word it is you want
tr ':' "\t" | # translate grep -c delimiter to tab for sort
sort -nr -k2 # sort Numeric, Reverse, "kolumn" 2
@mark-rushakoff
mark-rushakoff / leanpub_word_count.sh
Created April 5, 2013 14:58
Count words in your Leanpub book
#!/bin/sh
BOOK_SRC="${$1:-Book.txt}"
cat "$BOOK_SRC" | xargs cat | # dump out all the files in the book
sed 's/%%.*$//g' | # naively strip comment delimiter to end of line
wc -w | # print out the word count
@mark-rushakoff
mark-rushakoff / wrapped_func_benchmark_test.go
Created August 16, 2013 22:45
Is there a difference when using `go foo()` vs. `go func() { foo() }()`? (This never finished when I ran it on my MacBook Air.)
package wrapped_func
// Run this benchmark with `go test -bench=.`
import "testing"
func BenchmarkSendItClean(b *testing.B) {
total := b.N
c := make(chan bool)
for i := 0; i < total; i++ {