Skip to content

Instantly share code, notes, and snippets.

View benshimmin's full-sized avatar
🇪🇺
Bare ruin'd choirs, where late the sweet birds sang

Ben Shimmin benshimmin

🇪🇺
Bare ruin'd choirs, where late the sweet birds sang
View GitHub Profile
@benshimmin
benshimmin / gist:1397473
Created November 27, 2011 12:04
CoffeeScript to load SVG, extract all paths, and render them using Raphaël JS
$ ->
# load some SVG, call render() on successful load
$.ajax(
url : "data/file.svg"
dataType : "xml"
success : render
)
render = (data) ->
srcPaths = SVGExtractPaths.extract data
@benshimmin
benshimmin / gist:1883765
Created February 22, 2012 10:04
Simple lockfile implementation for AIR projects
package {
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
public class LockFile {
private var lock : File;
private var lockData : String = "LOCKED: " + new Date().toTimeString();
private var ensureAtomicity : Boolean;
@benshimmin
benshimmin / gist:1973525
Created March 4, 2012 15:27
Cross-browser custom cursors with Sass
// USAGE:
// To use a custom cursor with a path of css/cursors/custom.cur you would do this:
// @include custom-cursor(css/cursors/,custom)
@mixin custom-cursor($baseURL, $filename)
cursor : url($filename + ".cur"),url($baseURL + "/" + $filename + ".cur"),default
@benshimmin
benshimmin / gist:1992745
Created March 7, 2012 12:05
Kill a process which is accessing a file (whose name matches FILENAME) - use with caution!
lsof | grep FILENAME | kill -9 `awk '{print $2}'`
@benshimmin
benshimmin / Utils.coffee
Created March 11, 2012 12:23
Nice pattern for utility classes in CoffeeScript
Utils =
Math :
class MathUtils
@clamp : (num, min, max) ->
return min if num < min
return max if num > max
num
String :
@benshimmin
benshimmin / singleton.coffee
Created March 25, 2012 14:01
Singletons in CoffeeScript
# CoffeeScript makes this almost uniquely easy.
class Singleton
instance = undefined
@getInstance : ->
instance ?= new @
# And a singleton class can be subclassed elegantly too.
class SingletonTest extends Singleton
constructor : ->
@benshimmin
benshimmin / gist:2348702
Created April 10, 2012 06:15
Sinatra and cross-domain origins for local testing
# If you have a local test environment with a server running on (say) http://localhost:8888/
# and are also using Sinatra running on http://localhost:4567/ then you will most likely run
# into cross-domain problems communicating between the two via JavaScript. Here's a quick
# fix that will work beautifully for your local testing environment _but you should not use
# otherwise_!
require "sinatra"
before do
headers "Access-Control-Allow-Origin" => "*"
@benshimmin
benshimmin / gist:2488427
Created April 25, 2012 09:17
Backbone - determine whether a model's property has changed from its default
// Since Backbone.Model's hasChanged() function only works after "change" events...
Backbone.Model.prototype.hasDefaultChanged = function(prop) {
return this.defaults[prop] !== this.get(prop);
};
@benshimmin
benshimmin / gist:2694012
Created May 14, 2012 13:32
How to turn a regular anchor into a WebKit button
// Assuming you have markup like:
//
// <a class="stupid-button" href="#">I'm a fake button</a>
//
// ...you can use the following CSS to make it look like a regular WebKit button. Probably.
a.stupid-button
color : black
text-decoration : none
padding : 2px 6px
@benshimmin
benshimmin / gist:2780772
Last active October 5, 2015 08:47
One-liner to make DOM elements (like Backbone's; requires jQuery)
/* usage: var $el = make("div", {"class" : "foo"}, "bar"); // -> <div class="foo">bar</div> */
function make(t, a, c) { var e; return e = document.createElement(t), a && $(e).attr(a), c != null && $(e).html(c), e; }