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 / Array::indexOfArr.js
Last active August 29, 2015 14:01
Array::indexOfArr
Array.prototype.indexOfArr = function(search) {
var found = -1;
this.some(function(v, x) {
if(search.length > this.length - x) {
return true;
}
found = x;
this.some.call(search, function(sv, y) {
if(sv !== this[x+y]) {
found = -1;
var FBasync = {};
// For each method in the FB library
_.each(FB, function(fn, name) {
// Create an equivalent method in FBasync
FBasync[name] = function() {
// Grab the arguments the function was called with
var _args = arguments;
import Facebook from 'appkit/initializers/facebook';
var FacebookAuthenticator = Ember.SimpleAuth.Authenticators.OAuth2.extend({
authenticate: function() {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
_this.facebookCallback().then(function(response) {
var expiresAt = _this.absolutizeExpirationTime(response.expires_in);
@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();
@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 },

(function ($, window, undefined) {
$.fn.extend({
check2: function(option) {
var check2Class = 'check2',
conf = {
check2Class: check2,
offscreenClass: 'offscreen',
fontSize: '1.2em',
hasCheck2Class: [
@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...');
@jimmed
jimmed / new_gist_file
Created June 28, 2013 16:57
NAS todo list
1. Install Transmission
2. Install CouchPotato
  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 && mkdir .chef && echo "cookbook_path [ '/root/chef-repo/cookbooks' ]" > .chef/knife.rb
@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');