Skip to content

Instantly share code, notes, and snippets.

#!/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 / 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
@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 / 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 / javascript-complexity.md
Last active December 30, 2015 09:09
Managing JavaScript Complexity
@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 / 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 / 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 / Psycho MiWay bus driver.md
Last active December 26, 2015 08:08
Psycho MiWay bus driver

At 9:45am, Wednesday October 23rd, I was turning right from Skymark Ave to Explorer Drive.

There was a bus, 35AW, parked on Skymark with its hazard lights on, approximately 3 meters back from the intersection.

I passed the bus on the left, intending to turn right on Explorer, but before I could complete the pass, the bus started moving.

I was ahead of the bus, forward of its front left corner, and couldn’t get back into the right lane; further I believed the driver hadn’t seen me, as I could clearly see him and he showed no signs of acknowledging my presence, and I believed that I was in danger of being struck unless I made my presence known. I called “Hello!” to the window, which I could see was partially open.

The bus slammed on its brakes, and the driver blasted the horn at me while giving me the middle finger. I returned the gesture over my shoulder.

This is a really fast way to restore a large Postgres database by omiting the indexes and restoring them later (if necessary).

  1. Dump database.

    pg_dump -Fc --no-owner my_db -f ~/my_db.dump

  2. Create the summary files. One for the indexes and another for everything else.

pg_restore -l ~/my_db.dump | grep -v 'INDEX public' > ~/my_db.list