Skip to content

Instantly share code, notes, and snippets.

@evilstreak
evilstreak / gist:246187
Created December 1, 2009 09:42
Simple tabs code for thinjs
$( ".tabs" ).each( function() {
// a collection of all the tabs for closing over
var tabs = [];
// find all the anchor links inside
$( "a[href^='#']", this ).each( function() {
// find the element this anchor targets and stash it
var href = this.href.substring( this.href.lastIndexOf( "#" ) ),
tab = $( href )[ 0 ];
tabs.push( tab );
#!/bin/bash
function is-git? {
git status &> /dev/null
[ $? != 128 ]
}
function git-init-remote {
name=$(basename $PWD).git
path="~/repos/$name"
// usage: flusspferd tree.js grammar.peg inputfile
const peg = require( "PEG_generator" ),
fs = require( "fs-base" ),
system = require( "system" );
var grammar = fs.rawOpen( system.args[ 1 ], "r" ).readWhole(),
input = fs.rawOpen( system.args[ 2 ], "r" ).readWhole(),
names = eval( peg.generateParserThrowing( grammar ) ),
root = names[ 0 ],
#!/bin/sh
# Invoke like this:
# svn di --diff-cmd=./diffwarp.sh && cat .gitdiff | gitx && rm .gitdiff
#
# For easier use, stick diffwarp.sh in your path and alias the command
# alias svnx='svn di --diff-cmd=diffwarp.sh > /dev/null && cat .gitdiff | gitx && rm .gitdiff'
# Subversion provides the paths we need as the sixth and seventh
# parameters.
function points_on_a_line( from, to, gap ) {
// work out the difference in X and Y, and the hypotenuse
var dx = to.x - from.x,
dy = to.y - from.y,
h = Math.sqrt( dx*dx + dy*dy )
points = [],
// work out what proportion of the hypotenuse each step will be
step = gap / h,
d = 0,
i = 0;
@evilstreak
evilstreak / bar.t.js
Last active December 16, 2015 19:19
Bare bones example of a mocha test suite for markdown-js that'll run in the console and the browser.
// require modules under node.js; in a browser they'll already be present
if ( typeof chai === "undefined" ) { var chai = require( "chai" ); }
if ( typeof markdown === "undefined" ) { var markdown = require( "../lib/markdown" ); }
var assert = chai.assert,
// test wrapper to pass each a fresh markdown object
t = function( fn ) { return function() { fn( new markdown.Markdown() ); }; };
suite( "autolinking", function() {
test( "URL", t( function( md ) {
@evilstreak
evilstreak / DemoChain.lua
Last active July 29, 2019 02:28
Event Streams in Lua
function double( x )
return x * 2;
end
function square( x )
return x * x;
end
s = EventStream.new();
@evilstreak
evilstreak / gist:5523863
Last active March 29, 2016 22:55
Playing with simple prototypal inheritance in Lua
Object = {};
function Object:clone( o )
return setmetatable( o, { __index = self } );
end
function Object:instanceOf( parent )
local mt = getmetatable( self );
if mt == nil or mt.__index == nil then
require './lib/point.rb'
class Rectangle
DEFAULT_COLOR = Gosu::Color::WHITE
# The internal representation is two points (top-left and bottom-right)
attr_accessor :left, :top, :right, :bottom, :color
def self.from_center(window, center, width, height, color = DEFAULT_COLOR)
new(window, center.x - width / 2, center.y - height / 2,
module Eventable
def listen(event, method)
eventable_listeners[event] << method
end
def emit(event, *args)
eventable_listeners[event].each do |method|
method.call(*args)
end
end