Skip to content

Instantly share code, notes, and snippets.

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

@meagar
meagar / promises.md
Last active December 18, 2015 00:49
Promises.md

##JavaScript isn't threaded

  • Synchronous code locks up the browser
  • Asynchronous code frees up the browser but leads to...

##Async callback hell

"Return" values are no longer available to our synchronous code

@meagar
meagar / refresh-css.js
Last active October 13, 2015 12:38
Refresh only CSS via ctrl-R
/**
* Include via a <script> tag and reload CSS files via ctrl-R without a full-page refresh.
* Maintains your state, especially useful for JavaScript-based single-page apps
*
* Requires jQuery 1.6 or greater
*/
(function () {
"use strict";
// Part 1
document.getElementById('the_div' ).addEventListener('click', function(){ log('the_div!') }, true);
document.getElementById('the_list').addEventListener('click', function(){ log('the_list!') }, false);
document.getElementById('the_item').addEventListener('click', function(){ log('the_item!') }, true);
// Part 2
document.getElementById('the_div' ).addEventListener('click', function(){ log('the_div!') }, false);
document.getElementById('the_list').addEventListener('click', function(){ log('the_list!') }, false);
var Person = function(name) {
this.name = name;
};
// Part 2
Person.prototype.getName = function() {
return this.name;
};
var thomas = new Person('Thomas');
@meagar
meagar / gist:1206576
Created September 9, 2011 15:53
Caching wrapper redux
Function.prototype.cachify = function () {
var cache = {}, self = this;
return function (arg) {
if (arg in cache) {
console.info('cache hit');
return cache[arg];
}
return cache[arg] = self.call(self, arg);
};
@meagar
meagar / gist:1204679
Created September 8, 2011 20:54
Exercise 01 - functional vs OO
function logCar(car) {
console.info("I'm a", car.color, car.make);
}
function Car(make, color) {
this.make = make;
this.color = color;
}
Car.prototype.log = function () { logCar(this); }
@meagar
meagar / gist:1204660
Created September 8, 2011 20:47
Exercise 07 - add closure
function isPrime( num ) {
// everything but 1 can be prime
var prime = num != 1;
for ( var i = 2; i < num; i++ ) {
if ( num % i == 0 ) {
prime = false;
break;
}
}
return prime;