Skip to content

Instantly share code, notes, and snippets.

@edfuh
edfuh / js.TMsyntax
Created March 15, 2012 01:30
TextMate JS syntax file
{ scopeName = 'source.js';
comment = 'JavaScript Syntax: version 2.0';
fileTypes = ( 'js', 'htc', 'jsx' );
foldingStartMarker = '^.*\bfunction\s*(\w+\s*)?\([^\)]*\)(\s*\{[^\}]*)?\s*$';
foldingStopMarker = '^\s*\}';
patterns = (
{ name = 'meta.class.js';
comment = 'match stuff like: Sound.prototype = { É } when extending an object';
match = '([a-zA-Z_?.$][\w?.$]*)\.(prototype)\s*(=)\s*';
captures = {
$('iframe:not(:visible)').remove();
urls = ['https://edfuh.com', 'https://google.com']; i = 0;
[].slice.call(frames).forEach(function(f){ console.log(f.location.assign(urls[i++])) })
// Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({
routes: {
"": "index"
},
index: function() {
this.useLayout("main").setViews({
header: new UI.Views.Toolbar()
}).render();
@edfuh
edfuh / easy rgb to hex.js
Created May 28, 2013 17:36
I use this a lot
function rgbToHex (r, g, b) {
return [].slice.apply(arguments).map(function (n) {
return n.toString(16);
}).join('').toUpperCase();
}
@edfuh
edfuh / dumb.js
Created April 19, 2013 17:43
dumb stuff
setInterval( function(){
document.body.style.zoom = ((+document.body.style.zoom || 1) + 0.01)
},1000)
@edfuh
edfuh / gist:5390267
Created April 15, 2013 18:35
dumb dirty way to find if an object key exists in a deep object
keyExists = function(obj, structure) {
var F = function(){};
F.prototype = obj;
var parts = structure.split('.');
var testObj = new F;
for (var i = 0, j = parts.length; i < j; i++) {
if (!testObj[parts[i]]) {
@edfuh
edfuh / timer.js
Created March 9, 2013 23:01
simple countdown timer for some stuff
function Countdown(seconds, update, done) {
this.length = seconds;
this.update = update;
this.done = done;
}
Countdown.prototype.start = function () {
var self = this;
self.update(self.length);
@edfuh
edfuh / filter.js
Created March 17, 2012 00:11
Hacky ass ways to filter backbone collections
Backbone.Collection.extend({
// #sadface
// collection.sadFilter().invoke('save') <- TypeError
sadFilter : function (m) {
return this.filter(function (m) {
return m.get('happiness') < 1
})
},
// First option
// Wrap in underscore object
@edfuh
edfuh / pre-commit
Created November 22, 2011 23:56 — forked from mklabs/pre-commit
run jshint as git/hg hooks, NO COMMIT IF NO LINT FREE.
#!/usr/bin/env node
// todo: try to require jshint here, instead of spawning process, then fallback to spawning process.
var jshint = nrequire('jshint');
if (jshint) return process.exit(0);
// jshint not installed locally, spawn process instead.
// basically the same, but less pretty.
var exec = require('child_process').exec;
@edfuh
edfuh / gist:1299726
Created October 19, 2011 21:23
Turn any string into a start up band name
// 'toaster'.toStartUpBand();
String.prototype.toStartUpBand = function () {
return this.replace(/[^aeiuo]([aeiuo]{1})[^aeiuo]+$/g, function(m,m1){return m.replace(m1, '')}) + 'ly';
};