Skip to content

Instantly share code, notes, and snippets.

View jakobmattsson's full-sized avatar

Jakob Mattsson jakobmattsson

View GitHub Profile
@jakobmattsson
jakobmattsson / gist:570295
Created September 8, 2010 15:29
Run IE, Run!
$(function() {
var minDist = 100;
var target = document.getElementById('volatile');
if (target == null)
return;
target.style.position = "relative";
target.style.left = target.style.left || "0px";
target.style.top = target.style.top || "0px";
(function(c){var a={};var b=function(d,e,f){if(a[d]){fn=a[d]}else{if(typeof e=="undefined"){return false}fn=a[d]=new Function("obj",'var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push("'+e.replace(/[\r\t\n]/g," ").replace(/\"/g,'\\"').split("<%").join("\t").replace(/((^|%>)[^\t]*)/g,"$1\r").replace(/\t=(.*?)%>/g,'",$1,"').split("\t").join('");').split("%>").join('p.push("').split("\r").join("")+"\");}return p.join('');")}if(typeof f!="undefined"){return fn(f)}else{return fn}};Sammy=Sammy||{};Sammy.Template=function(f,d){var e=function(h,i,g){if(typeof g=="undefined"){g=h}return b(g,h,c.extend({},this,i))};if(!d){d="template"}f.helper(d,e)}})(jQuery);
@jakobmattsson
jakobmattsson / gist:1046639
Created June 25, 2011 16:29
Function returning a list of strings describing the current browser
var whichBrowser = function() {
var ua = navigator.userAgent, p = {}, b = {}, e = {};
// detect platform
if (/Windows/.test(ua)) {
p.name = 'win';
p.win = true;
} else if (/Mac/.test(ua)) {
p.name = 'mac';
p.mac = true;
@jakobmattsson
jakobmattsson / queue.js
Created March 18, 2012 15:08
Function.prototype.queue
var queue = function(f) {
var queue = [];
var running = false;
var initiate = function() {
if (running || queue.length == 0) {
return;
}
running = true;
@jakobmattsson
jakobmattsson / propagate.js
Created March 18, 2012 18:49
Propagating async javascript errors
var propagate = function(callback, f) {
return function(err) {
if (err) {
callback(err);
return;
}
return f.apply(this, Array.prototype.slice.call(arguments, 1));
};
};
_ = require 'underscore'
semver = require 'semver'
readInstalled = require 'read-installed'
expectedPackages = (pkgJson) ->
pack = require(pkgJson)
devDeps = pack.devDependencies || {}
deps = pack.dependencies || {}
_.extend({}, devDeps, deps)
@jakobmattsson
jakobmattsson / getFile.coffee
Last active December 23, 2015 03:39
getFile
fs = require 'fs'
urlLib = require 'url'
path = require 'path'
mkdirp = require 'mkdirp'
downloader = require 'downloader'
exports.get = ({ url, dir, onDownload }, callback) ->
onDownload ?= (callback) -> callback()
{pathname} = urlLib.parse(url)
@jakobmattsson
jakobmattsson / getSelenium.coffee
Created September 15, 2013 23:54
getSelenium.coffee
getfile = require '../lib/getfile'
getfile.get
url: 'http://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar'
dir: '../.selenium'
onDownload: (callback) ->
console.log "Installing selenium...."
callback()
, (err, filepath) ->
return console.log(err) if err?
@jakobmattsson
jakobmattsson / deps.coffee
Last active December 24, 2015 19:49
Run this is a node-project to get a list of all repeated dependencies
fs = require 'fs'
_ = require 'underscore'
{exec} = require 'child_process'
exec 'npm ls', (err, output) ->
return console.log(err) if err?
lines = output.split('\n').slice(1, -2)
packages = lines.map (x) ->
@jakobmattsson
jakobmattsson / gist:7083975
Created October 21, 2013 13:34
Cutting an image into equally sized parts and for each image shaving off a bit on the top and bottom, resizing them and extending their canvas sizes.
convert tweaked.png -crop 729x870 -shave 0x80 -resize 80x70 -gravity East -extent 80x70 tiles_%d.png