Skip to content

Instantly share code, notes, and snippets.

View jimmed's full-sized avatar
:octocat:
#purrprogramming

Jim O'Brien jimmed

:octocat:
#purrprogramming
View GitHub Profile
@jimmed
jimmed / Cakefile
Last active December 14, 2015 05:48
Nifty logging function
# Handy log function
log = (msg, indent, type = 'log') -> console[type] ('\t' for i in [0..indent]).join(''), msg
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
awful.rules = require("awful.rules")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
@jimmed
jimmed / jquery.app.js
Last active December 14, 2015 16:29
ObjectKeys
$.extend(dust.helpers, {
/**
* {@objectKeys input=someObject}
* {key}: {value}<br />
* {/objectKeys}
*/
"objectKeys": function(chunk, context, bodies, params) {
params = params || {};
if(!$.isPlainObject(params.input)) {
console.warn('Input parameter to @objectKeys must be a plain object');
@jimmed
jimmed / TellAFriend.md
Last active December 15, 2015 07:19
TellAFriend.md

Tell A Friend

Let's take a look at the original code.

<script>document.write('<a target="_blank" href="YOURFORMLINK&referrer='+document.URL+'"'+'>Tell a Friend</a>');</script>

It's not the tidiest or most useable code in the world, nor is it the fastest. Let's put this through jsbeautifier -- an invaluable resource -- and see how it looks. We'll put it back to being a one-liner at the end.

<script>

document.write('Tell a Friend');

  1. Set up a vanilla Ubuntu Server VM or EC2 instance, then sudo su
  2. Install Chef: curl -L https://www.opscode.com/chef/install.sh | bash
  3. Copy the Chef Repository: wget http://github.com/opscode/chef-repo/tarball/master && tar -zxf master && mv opscode-chef-repo* chef-repo && rm master
  4. Create a cookbook directory: cd chef-repo &amp;&amp; mkdir .chef &amp;&amp; echo "cookbook_path [ '/root/chef-repo/cookbooks' ]" &gt; .chef/knife.rb
@jimmed
jimmed / new_gist_file
Created June 28, 2013 16:57
NAS todo list
1. Install Transmission
2. Install CouchPotato
@jimmed
jimmed / signupMigrate.js
Created July 10, 2013 19:38
Signup Form Migration
/*
* Self_configs migration tool
* ==
* 1. Visit the site you wish to migrate.
* 2. Run this script in the Chrome/Firebug console
* 3. You will receive some delicious SQL to run on your customer DB
*/
(function(undefined) {
console.info('Calling APIs...');
(function ($, window, undefined) {
$.fn.extend({
check2: function(option) {
var check2Class = 'check2',
conf = {
check2Class: check2,
offscreenClass: 'offscreen',
fontSize: '1.2em',
hasCheck2Class: [
@jimmed
jimmed / README.md
Last active October 7, 2016 10:44
An extension for underscore.js to generate tree structures based on Collections.

_.tree

_.tree is an extension for underscore.js, which converts flat Collections into tree structures.

Example

Take the following collection. Each item in the collection has an id and a parent_id, describing how it relates to other items.

var input = [

{ id: 1, name: 'Grandfather', parent_id: 0 },

@jimmed
jimmed / $.Deferred.js
Last active December 30, 2015 01:18
Converting Promises
var someTask = $.Deferred();
doSomethingAsync(function(result) {
someTask.resolve(result);
});
return someTask.promise();
// becomes
var someTask = Promise.defer();