Skip to content

Instantly share code, notes, and snippets.

View togakangaroo's full-sized avatar

George Mauer togakangaroo

View GitHub Profile
@togakangaroo
togakangaroo / gist:1664107
Created January 23, 2012 16:29
Methods of Removing Redundant Code

Common methods of removing redundant code scored by

  • Ease of Implementation (lower is more difficult)
  • Dont Repeat Yourself (lower involves more repetition and therefore more prone to bugs)
  • Loose Coupling (lower involves higher degrees of coupling and therefore more prone to bugs)
4 4 2 Extract static method
Ease DRY Loose Coupling Refactoring Method
5 1 5 Copy paste
@togakangaroo
togakangaroo / gist:1676930
Created January 25, 2012 15:59
Javascript functions returning functions - when you're being an asshole
cell.draggable({
helper: "clone",
start: function() { _.each(self.selection(), function(s){ s.cell.addClass('dragged')}) },
stop: function() { _.each(self.selection(), function(s){ s.cell.removeClass('dragged')}) }
});
// Looks good but I can clean that up!
var applyDrag = function(op){
return function() { _.each(self.selection(), function(s){ s.cell[op+'Class']('dragged')}) }
@togakangaroo
togakangaroo / gist:1761525
Created February 7, 2012 19:53
Javascript hashmap vs. if vs. case
//console.time implementation for IE
if (window.console && typeof (window.console.time) == "undefined") {
console.time = function (name, reset) {
if (!name) {
return;
}
var time = new Date().getTime();
if (!console.timeCounters) {
console.timeCounters = {}
};
@togakangaroo
togakangaroo / underscorify_boookmarklet.js
Created May 10, 2012 21:12
Underscorify bookmarklet
javascript: (function(){var el=document.createElement('div'),b=document.getElementsByTagName('body')[0];otherlib=false,msg='';el.style.position='fixed';el.style.height='32px';el.style.width='220px';el.style.marginLeft='-110px';el.style.top='0';el.style.left='50%';el.style.padding='5px 10px';el.style.zIndex=1001;el.style.fontSize='12px';el.style.color='#222';el.style.backgroundColor='#f99';if(typeof _ !='undefined'){msg='This page already using Underscore v'+_.VERSION;return showMsg();} function getScript(url,success){var script=document.createElement('script');script.src=url;var head=document.getElementsByTagName('head')[0],done=false;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){done=true;success();script.onload=script.onreadystatechange=null;head.removeChild(script);}};head.appendChild(script);} getScript('http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js',function(){if(typeof _ =='undefined'
@togakangaroo
togakangaroo / tiny-flow-control.coffee
Created June 22, 2012 20:44
I guess its my turn to write a flow control library
###
My tiny little flow control library.
Usage:
$.Deferred.invoke func, context, ...args
func - Function with its two final parameters being onSuccess and onError
context - context to bind to 'this' when func is invoked
args - flat list of arguments
Returns:
jQuery Deferred object
ul, li {
margin: 0;
padding: 0;
}
ul, li {
margin: 0;
padding: 0;
}
ul, li {
margin: 0;
padding: 10px;
list-style: none;
}
@togakangaroo
togakangaroo / gist:3133127
Created July 18, 2012 00:16
A very simple pretty checkbox plugin
$.widget 'someApp.prettyCheckbox',
_create: ->
if not @element.is ':checkbox'
return console.error "Expect widget to be called on a checkbox element", this, this.element
@wrapper = $('<div class=prettyCheckbox-wrapper>')
.css(position: 'relative', display: 'inline-block')
@element
.css(padding: 0, border: 0, opacity: 0, position: 'absolute', left: 0, top: 0)
@prettyBox = $('<div class=prettyCheckbox>')
@togakangaroo
togakangaroo / gist:3318552
Created August 10, 2012 22:10
My Powershell $profile
New-PSDrive HOST -PSProvider FileSystem -Root \\VBOXSVR\georgemauer
$tempDir = ([system.io.path]::GetTempPath())
function edit
{
param( [Parameter(ValueFromPipeline=$true,Position=0)] $file )
begin { set-alias EDITOR 'W:\tools\sublime_text.bat' }
process { EDITOR $file }
}
function Coalesce-Args {