Skip to content

Instantly share code, notes, and snippets.

View FireyFly's full-sized avatar

FireFly FireyFly

View GitHub Profile
@FireyFly
FireyFly / rc.lua
Created June 1, 2012 09:25 — forked from anonymous/rc.lua themetheme.lua.txt
rc.lua theme/theme.lua
-- Standard awesome library
require("awful")
require("awful.autofocus")
require("awful.rules")
-- Theme handling library
require("beautiful")
-- Notification library
require("naughty")
require("vicious")
require("menu")
@FireyFly
FireyFly / emitter.js
Created June 5, 2012 10:15
Really simple node-like event emitter
// Definition
function EventEmitter() {
var handlers = {}
this.on = function (event, cb) {
if (!handlers[event]) {
handlers[event] = []
}
handlers[event].push(cb)
}
@FireyFly
FireyFly / blah.js
Created June 8, 2012 21:25
Using object extension to hide/override properties
var Foo = Base.extend({
init: function() {
// ...
Base.init.call(this)
}
})
// ...where Base.extend is defined as in https://gist.github.com/2000920
@FireyFly
FireyFly / example.js
Last active October 6, 2015 03:38
Using `extend` for "subclassing"
var Person = Base.inherit({
// missing: name
// A person can tell you its name.
talk: function() {
return "Hello, I'm " + this.name
}
})
var WorkingPerson = Person.inherit({
var foo = { hello : 10
, world : 20
, foo : 30
}
var blah = {
meh: 10,
qux: "hello world",
method: function() {
var f = wrapFunc(function() {
function Fraction(nom, denom) {
this.nominator = nom
this.denominator = denom
}
Fraction.prototype['*'] = function(other) {
return new Fraction(this.nominator * other.nominator,
this.denominator * other.denominator)
}
@FireyFly
FireyFly / gist:2941356
Created June 16, 2012 13:38 — forked from robotlolita/gist:2941344
Get a random Y position for a new enemy being spawned, which is NOT "crowded" (no other active enemy must have the same rough Y position).
function getYPositionNotCrowded() {
var maxCount = 1000
, height = 4
, i = 0
, y
do {
y = nextYPosition()
if (++i > maxCount) { throw new Error("No position found!") }
@FireyFly
FireyFly / haste.sh
Created June 18, 2012 12:52
Utilities
#!/bin/sh
filename=""
case $# in
0) # no arguments; read from stdin into a randomly-named temp file.
tmpfile="/tmp/haste-$(uuidgen | cut -d- -f1)"
filename="$tmpfile"
cat >"$tmpfile"
;;
@FireyFly
FireyFly / options.lua
Created June 19, 2012 21:41
Luakit module to interact with "globals" options from the browser itself.
----------------------------------------------------------------
-- Manages global options --
-- Copyright © 2012 Jonas Höglund <[email protected]> --
----------------------------------------------------------------
-- Grab environment we need
local string = string
local type = type
local pairs = pairs
local assert = assert
//-- Definition
Function.prototype.compose = function (/* ...args */) {
var args = Array.prototype.slice.call(arguments)
, funs = [ this ].concat(args)
return function (/* ... */) {
return funs.reduceRight(function (args, f) {
return [ f.apply(null, args) ]
}, arguments)[0]
}