Skip to content

Instantly share code, notes, and snippets.

View shawndumas's full-sized avatar

Shawn Dumas shawndumas

View GitHub Profile
@shawndumas
shawndumas / setStyle.js
Created December 2, 2011 18:04
Set Element's Style
//setStyle(
// document.getElementById('divId'),
// 'height: 180px; text-align: left; overflow-y: scroll;'
//);
var setStyle = function (elm, style) {
var rules = (function (style) {
var css, v,
rules = {},
div = document.createElement('div');
@shawndumas
shawndumas / starfighter.lua
Created May 21, 2012 12:22
Codea Game: StarFighter
--# HeroAttack
HeroAttack = class()
function HeroAttack:init(hero)
self.duration = 0.5
self.currentTime = 0
self.endTime = self.currentTime + self.duration
self.hero = hero
self.size = hero.size
@shawndumas
shawndumas / waitUtill.js
Created June 9, 2012 00:19
WaitUntil...
// Play with it here --> http://jsfiddle.net/Pdft8/2/
Function.waitUntil = function(fn, condition, interval, stopOnReady) {
var defaults = {
pageReady: function() {
return (/complete|loaded|interactive/).test(document.readyState);
},
pageLoad: function() {
return (/complete|loaded/).test(document.readyState);
}
@shawndumas
shawndumas / joseify.js
Created June 28, 2012 15:16
Delimited string decoder / encoder
// [
// { 'id': '123', 'amt': '300', 'price': '3' },
// { 'id': '124', 'amt': '400', 'price': '4' },
// { 'id': '125', 'amt': '500', 'price': '5' }
// ].joseify();
//
// ==> '123|300|3[124|400|4[125|500|5'
Array.prototype.joseify = function (fieldSep, rowSep) {
fieldSep = fieldSep || '|';
rowSep = rowSep || '[';
function User(first, last){
if ( !(this instanceof User) )
return new User(first, last);
this.name = first + " " + last;
}
var name = "Resig";
var user = User("John", name);
@shawndumas
shawndumas / lodar.js
Created August 14, 2012 21:28
JavaScript Script Loader
;(function (name, self, d) {
self[name] = function (src, cb) {
cb = cb || function () {};
var newScriptTag = d.createElement('script'),
firstScriptTag = d.getElementsByTagName('script')[0];
newScriptTag.src = src;
newScriptTag.async = true;
newScriptTag.onload = newScriptTag.onreadystatechange = function () {
@shawndumas
shawndumas / concat.js
Created August 17, 2012 14:10
Clean, Fast, String Join
var s = ''.concat(
'<div class="heading">',
'<div class="firstname">',
'{firstname}',
'</div>',
'<div class="lastname">',
'{lastname}',
'</div>',
'</div>'
);
@shawndumas
shawndumas / notBad.js
Created August 17, 2012 14:12
Evaluate Using a Little Trick
var s = 'var i = 10; while (i--) { console.log(i); }';
(new Function(s))();
@shawndumas
shawndumas / PartialFunction.scala
Created May 8, 2013 15:16
Partial Functions in Scala
val doubleEvenNumbers = new PartialFunction[Int, Int] {
def isDefinedAt(x: Int) = x % 2 == 0
def apply(v1: Int) = v1 * 2
}
val tripleOddNumbers = new PartialFunction[Int, Int] {
def isDefinedAt(x: Int) = x % 2 != 0
def apply(v1: Int) = v1 * 3
}
@shawndumas
shawndumas / .gitconfig
Created August 5, 2013 19:08
Using WinMerge as the git Diff/Merge Tool on Windows 64bit
[mergetool]
prompt = false
keepBackup = false
keepTemporaries = false
[merge]
tool = winmerge
[mergetool "winmerge"]
name = WinMerge