Skip to content

Instantly share code, notes, and snippets.

View iamdustan's full-sized avatar

Dustan Kasten iamdustan

View GitHub Profile
@iamdustan
iamdustan / pluck-autoslug-badge-creation.js
Created September 29, 2011 15:36
Bookmarklet: Autoslug Badge and Level Keys based on the Name in Demand Media's Pluck v1.0 CMW
/*
* Autoslug's because we'd all rather be lazy.
* The CMW uses Prototype. I like jQuery.
*/
/* @Source */
(function(d,t){
var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js';
s.parentNode.insertBefore(g,s);
@iamdustan
iamdustan / blacksmith.js
Created April 11, 2012 02:52
Concerning blacksmith static site generator losing the doctype through the generatation process.
/* ~ line 122 +
* First attempt to add the doctype was to hardcode it in place of smith.window.document.doctype.
* This added the doctype to the output argument of each renderer, but that didn’t apply to what was written to disk.
*/
smith.renderers.forEach( function (renderer) {
// Grabs the name given to the generator.
var name = Object.keys(renderer)[0];
smith.log.info('Rendering "'+name+'"');
@iamdustan
iamdustan / yepnope.js
Created June 5, 2012 15:01
Categorizr.js and yepnope.js are best friends.
yepnope([
{
test : categorizr.isMobile,
, yep : ['mobile-specific.js', 'mobile-specific.css']
}
, {
test : categorizr.isTablet,
, yep : ['tablet-specific.js', 'tablet-specifc.css']
}
, {
@iamdustan
iamdustan / gist:2960278
Created June 20, 2012 14:53
porcelain and plumbing examples of git commands.
# PORCELAIN
# set an upstream tracking branch.
git push -u origin development
# get an external URL and make a copy of it on your machine
git clone git@github.com:Skookum/mason.git
# PLUMBING
@iamdustan
iamdustan / gist:2960285
Created June 20, 2012 14:55
hub examples
# It is smart enough to know that this is a Github user and requests
# the appropriate URL
git pull Skookum/categorizr.js
# Use your git text editor to compose pull requests. No longer do you
# need to break out of your normal workflow in terminal to go to
# github.com to write your pull request.
git pull request
# Create a git repo on github.com
((name, context, definition) ->
if typeof module isnt "undefined"
module.exports = definition(name, context)
else if typeof define is "function" and typeof define.amd is "object"
define definition
else
context[name] = definition(name, context)
) "moduleName", this, (name, context) ->
# module code it up
@iamdustan
iamdustan / app.routes.js
Created August 9, 2012 13:26
Really ugly quick hack at route extending a componentized express app.
var path = require('path');
module.exports = function(app) {
app.get('/dashboard', app.user.loggedIn, function(req, res) {
return res.render(path.join(__dirname, 'home/dashboard'), {
user: req.session.user
});
});
$('body').on('click', 'a[data-toggle=tab]', function(e) {
var self = $(this)
, target = self.attr('href')
, actives = self.closest('.tabs').find('.active')
actives.removeClass('active')
self.addClass('active')
target.addClass('active')
})
// option 1
var Subscription = function (plan) {
var self = this;
// statics
_.each(['dropdown_text full_rate id months name renew_rate special type'].split(' '),
function(prop) { this[prop] = ko.observable(plan[prop]); })
this.monthly_rate = ko.computed(function () {
return (self.full_rate() / self.months()).toFixed(2);
});
@iamdustan
iamdustan / Element.on.js
Created September 5, 2012 19:00
Tiny event delegation and event binding by extending Element with Element.prototype.on. Depends upon `matchesSelector`. Polyfill here: https://gist.github.com/3062955
(function(El) {
El.on = function(type, el, callback) {
if ('function' === typeof el) {
callback = el
el = null
}
this.addEventListener(type, function (e) {
if (!el || e.target.matchesSelector(el))
return callback(e)