Skip to content

Instantly share code, notes, and snippets.

View emjayess's full-sized avatar
💭
🪞 mirroring repos from gitlab

Matthew J. Sorenson emjayess

💭
🪞 mirroring repos from gitlab
View GitHub Profile
//artificially delay a javascript redirect w/anonymous function
//n represents delay in seconds
(function(){
var i,c=0,n=3;
i=window.setInterval(function(){
if(c++==n){
window.clearInterval(i);
top.location='http://redirect-here.tld/';
}
function $arr(xargs) {
return Array.prototype.slice.call(xargs);
}
//sample usage:
function someotherfn(arg1,arg2,arg3){
$args = $arr(arguments);
$args.sort();
}
@emjayess
emjayess / emstrong.css
Created November 1, 2010 17:59
this was an actual style rule on a site I inherited. :\
em {
font-weight: bold;
font-style: normal;
}
// Cross-browser object.watch and object.unwatch
// object.watch
if (!Object.prototype.watch) {
Object.prototype.watch = function (prop, handler) {
var oldval = this[prop], newval = oldval,
getter = function () {
return newval;
},
setter = function (val) {
@emjayess
emjayess / ternary.js
Created December 1, 2010 17:34
javascript's flexible ternary
// the agility of javascript's ternary operation...
// lots of folks don't seem aware of the subsequent assignments available
function ternary(a,b) {
var c,d,tis='';
c = (d = a==b) ? tis='tis true' : tis='tis false';
return [c,d,tis];
}
console.log(ternary(true,true));
console.log(ternary(true,false));
@emjayess
emjayess / mustache-cfc.test.cfm
Created December 28, 2010 23:25
this is going to make my life a little (ok, a lot) easier!...
<cfscript>
// require https://github.com/pmcelhaney/Mustache.cfc
mustache = createobject('component','cfc/mustache');//dump(mustache);
//view template:
hello_templ = '<h1>Hello, {{thing}}</h1>';
//model object:
hello_model = {
thing = 'Mustache'
/*!
* JavaScript whatevCache - v0.2pre - 12/30/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// whatevCache.set( key, value [, ttl ] );
@emjayess
emjayess / jquery.foo.js
Created January 18, 2011 23:34
boilerplate js for jquery plugin authoring
// replace 'foo' with the name of the plugin, etc
(function($){
$.fn.foo = function(opts) {
var settings = $.extend({}, $.fn.foo.defaults, opts);
return this.each(function() {
var $this = $(this);
// plugin code here...
});
};
@emjayess
emjayess / goldfusion.cfm
Created January 22, 2011 20:11
did you ever think coldfusion could achieve such elegance?!
<cfscript>
writeoutput(
stache.render(
$.getTMPL(mustache_path & "navigation.mustache"),
$.getJSON(fixtures_path & "navigation.json")
)
);
</cfscript>
@emjayess
emjayess / chunkify.pl
Created March 4, 2011 22:58
one basic approach to chunking/parsing a csv using Text::CSV
#!/usr/bin/perl
# modes
use strict;
use warnings;
# modules
use Text::CSV;
my $csv = 'DATA.TXT';