Skip to content

Instantly share code, notes, and snippets.

View acrookston's full-sized avatar
👨‍💻
Coding!

Andrew Crookston acrookston

👨‍💻
Coding!
View GitHub Profile
@acrookston
acrookston / gist:1446888
Created December 8, 2011 12:45
javascript log
// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
def redirect_mobile(url = "http://detectmobilebrowser.com/mobile")
redirect_to url if /android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.match(request.user_agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|j
@acrookston
acrookston / scroll.js
Created May 16, 2012 21:42
Small scrolling script for fun. Not sure how well it works. Please contribute if you have ideas.
Scrolling = {};
$.extend(Scrolling, {
smoothScrollTo: function(top) {
var sm_speed = 300;
var sm_runs = 0;
var sm_last = -1; // don't use 0, b/c sm_window_top can be 0
var sm_window_top = $(window).scrollTop();
var sm_down = (top > sm_window_top);
var sm_each_step = (sm_down ? top - sm_window_top : sm_window_top - top) / (sm_speed / 13);
var sm_scroll = function() {
@acrookston
acrookston / scroll.js
Created May 17, 2012 16:15 — forked from arnorhs/scroll.js
Small scrolling script for fun. Not sure how well it works. Please contribute if you have ideas.
// muhaha.. changed all the code
// maybe this version handles scrolling to the bottom edge of a document a little better
// still not satisfied with the speed variable.. should that be higher == more speed, perhaps? or pixels per second?
// sorry about the opinionated style changes
Scrolling = {
smoothScrollTo: function(target_top) {
// ensure that we never scroll further than viewport size from bottom of the doc
target_top = Math.min(target_top, Math.max($(document).height(), $(window).height()) - $(window).height());
var speed = 30,
#!/bin/bash
git diff --name-only origin/master | grep '\.png$' | xargs -I xxx -P 10 -t pngbai xxx xxx2
echo "Replacing files"
find . -iname *.png2 -exec bash -c 'echo {} `dirname {}`/`basename {} .png2`.png' \;
find . -iname *.png2 -exec bash -c 'mv {} `dirname {}`/`basename {} .png2`.png' \;
echo "Removing leftovers"
find . -iname *.png2.png -exec bash -c 'echo {}' \;
class Player
def od(dir)
return dir == :backward ? :forward : :backward
end
def play_turn(warrior)
w = warrior
@direction = :forward if @direction == nil
@back = 0 if @back == nil
@rest = false if @rest == nil
@acrookston
acrookston / growth-hacking.md
Created August 27, 2013 17:22
Summary of The Definitive Guide to Growth Hacking
@acrookston
acrookston / pngbai
Last active December 24, 2015 22:59
#!/bin/sh
## Packages:
# brew install pngcrush optipng advancecomp
# brew install https://gist.github.com/acrookston/7726731/raw/3e3ce6c177a450c375e3622636f4d55bbe5289f6/pngout.rb
function usage {
echo "Usage: $0 infile outfile"
exit 1
}
#!/bin/bash
# Depends on pngbai script: https://gist.github.com/acrookston/6877287
# And don't forget to install pngbai's dependencies (documeted there)
FILES=`git diff --name-only origin/master | grep '\.png$'`
for file in $FILES; do
echo "$file"
git add $file
pngbai $file "${file}2"
@acrookston
acrookston / parse_colors.rb
Last active December 26, 2015 20:29
Cross-posting from https://forrst.com/posts/Collecting_colours_from_an_image_Ruby-Lgo Collecting colours from an image with Ruby
require 'rmagick'
number_of_colors = 100
file_path = "/path/to/file.jpg"
begin
temp_file = Magick::Image.read(file_path).first.quantize(number_of_colors)
pixels = {}
pixel_count = 0
temp_file.each_pixel do |p,c,r|
pixel_count += 1
pix = p.to_color(Magick::AllCompliance, false, 8)