Skip to content

Instantly share code, notes, and snippets.

View tobyhede's full-sized avatar
👨‍🚀
...

Toby Hede tobyhede

👨‍🚀
...
View GitHub Profile
@tobyhede
tobyhede / gist:3890243
Last active October 11, 2015 16:58
Dump and restore postgres to remote server
Pipe directly to remote server
pg_dump -C -U dbuser {DBNAME} | psql -h xxx.xxx.xxx.xx -U {DBUSER} >> restore.log
And with passwords as required
PGPASSWORD="{DBPASSWORD}" pg_dump -C -U dbuser {DBNAME} | PGPASSWORD="{DBPASSWORD}" psql -h xxx.xxx.xxx.xx -U {DBUSER} >> restore.log
@tobyhede
tobyhede / reset-iptables.sh
Created October 8, 2012 01:26
Reset IPTABLES
#!/bin/sh
echo "Reset iptables..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
@tobyhede
tobyhede / postgres.md
Created October 3, 2012 07:00
Postgres Tuning

Cache Hit Ratio

SELECT 
  sum(heap_blks_read) as heap_read,
  sum(heap_blks_hit)  as heap_hit,
  (sum(heap_blks_hit) - sum(heap_blks_read)) / sum(heap_blks_hit) as ratio
FROM 
  pg_statio_user_tables;
@tobyhede
tobyhede / pedantically_commented_playbook.yml
Created September 26, 2012 01:47 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@tobyhede
tobyhede / db.md
Created August 6, 2012 22:42
Heoku Database Management

Note: These assume that pgbackups is activated for the app on heroku.

Snapshot & Local Restore

Snapshot the db and restore to your LOCAL database (about a zillion times faster than db:pull)

curl -o latest.dump  `heroku pgbackups:url --app {APP_NAME}`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U {USER} -d {DB} latest.dump
@tobyhede
tobyhede / clj->js.cljs
Created July 29, 2012 01:52
clj->js - convert ClojureScript objects into JavaScript equivalents
(defn clj->js
"Recursively transforms ClojureScript maps into Javascript objects,
other ClojureScript colls into JavaScript arrays, and ClojureScript
keywords into JavaScript strings."
[x]
(cond
(string? x) x
(keyword? x) (name x)
(map? x) (.-strobj (reduce (fn [m [k v]]
@tobyhede
tobyhede / gist:3179978
Created July 26, 2012 02:53
Ruby/Rails date format cheat sheet
From http://linux.die.net/man/3/strftime
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%e - Day of the month without leading 0 (1..31)
%g - Year in YY (00-99)
@tobyhede
tobyhede / index.txt
Created June 19, 2012 10:22 — forked from aschoerk/index.txt
Ruby/Clojure analogs
For each Ruby module/class, we have Ruby methods on the left and the equivalent
Clojure functions and/or relevant notes are on the right.
For clojure functions, symbols indicate existing method definitions, in the
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master,
ruby-to-clojure.*/* functions can be obtained from the source files in this
gist.
If no method symbol is given, we use the following notation:
@tobyhede
tobyhede / .rspec
Created June 10, 2012 00:40 — forked from coreyhaines/.rspec
Loading just active record
--colour
-I app
@tobyhede
tobyhede / postsql.sql
Created May 17, 2012 03:08
PostgreSQL as JSON Document Store
-- PostgreSQL 9.2 beta (for the new JSON datatype)
-- You can actually use an earlier version and a TEXT type too
-- PL/V8 http://code.google.com/p/plv8js/wiki/PLV8
-- Inspired by
-- http://people.planetpostgresql.org/andrew/index.php?/archives/249-Using-PLV8-to-index-JSON.html
-- http://ssql-pgaustin.herokuapp.com/#1
-- JSON Types need to be mapped into corresponding PG types
--