Skip to content

Instantly share code, notes, and snippets.

@meagar
meagar / promises.coffee
Last active December 26, 2015 22:09
A simply way of DRYing up promise-returning functions
# There's an incredibly common pattern when using promises:
#
# myFunction: ->
# dfd = $.Deferrred()
#
# $.ajax "wherever"
# .done() ->
# dfd.resolve("yep")
# .fail() ->
# dfd.reject("nope")
@meagar
meagar / bbget.md
Last active December 29, 2015 08:09
Allow Backbone's `get` to return multiple values

Improving Backbone's get to accept multiple arguments

CoffeeScript makes this work well:

[name, age] = user.get('name', 'age')

It would be trivially easy to allow Pam.Model's get to override Backbone's get to support this

@meagar
meagar / CoffeeScript Gotchas.md
Last active December 29, 2015 11:19
CoffeeScript gotcha - implicit objects on multiple lines

A short list of CoffeeScript gotcha's I've encountered writing CoffeeScript professionally.

These are not problems with CoffeeScript, rather they are strange one-off situations where, especially coming from Ruby, differences in CoffeeScript's syntax have led to unexpected JavaScript.

@meagar
meagar / javascript-complexity.md
Last active December 30, 2015 09:09
Managing JavaScript Complexity
@meagar
meagar / gist:8027073
Created December 18, 2013 18:14
Simple rake progress bar
# Use:
#
# # Pass an emuerable to #new
#
# users = User.active
# RakeProgrssBar.new(users) do |user|
# user.do_something_amazing
# end
#
#
@meagar
meagar / jsoffline.md
Last active August 14, 2018 09:28
Taking JavaScript Offline

Note: this presentation was written for Gistdeck. Add the bookmarklet, come back to this gist, click the bookmarklet, then use the arrow keys to navigate.

Note2: See https://github.com/meagar/taking-javascript-offline for code examples; any time a string like 2-basic-caching appears, that's a branch which supports that slide

Taking JavaScript Offline

Who am I?

@meagar

@meagar
meagar / rebase.md
Created April 30, 2014 16:01
Ultimate rebase-onto-master guide

Rebase "web-123-my-branch" onto master:

if you're the only person who is working on a branch...

$ git checkout web-123-my-branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git rebase origin/master # perform the rebase onto the current state of master
  # for each conflict, edit file, resolve conflicts, git add -u <file>, git rebase --continue
$ git push -f origin web-123-my-branch # overwrite remote branch with newly rebase branch
#!/usr/bin/env ruby
#
# This is a Git pre-commit hook.
#
# Reject commits that contain any of the following strings:
# # NO COMMIT | // NO COMMIT | #NOCOMMIT | //NOCOMMIT | etc
# debugger
# binding.pry
# console.log
@meagar
meagar / legacy_branches.rb
Created September 24, 2014 14:33
show legacy branches in a git repo
require 'time'
DAY = 60 * 60 * 24
def print_branches(branches)
by_author = Hash.new { |hash,key| hash[key] = {} }
branches.each do |branch|
lines = `git show -s --pretty=medium #{branch}`.lines
# commit d8f1e9d4c755d46192db635e964a9b04d6882f90
@meagar
meagar / keybase.md
Created October 8, 2014 21:25
keybase.md

Keybase proof

I hereby claim:

  • I am meagar on github.
  • I am meagar (https://keybase.io/meagar) on keybase.
  • I have a public key whose fingerprint is 6CBA F179 B60D D17D A8DA 9A06 B227 183C DC1F A2E5

To claim this, I am signing this object: