Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍🚀
...

Toby Hede tobyhede

👨‍🚀
...
View GitHub Profile
@tobyhede
tobyhede / gist:3179978
Created Jul 26, 2012
Ruby/Rails date format cheat sheet
View gist:3179978
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 / postsql.sql
Created May 17, 2012
PostgreSQL as JSON Document Store
View postsql.sql
-- 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
--
View adr.md

Title

Short present tense imperative phrase, less than 50 characters, like a git commit message.

Status

proposed, accepted, rejected, deprecated, superseded, etc.

Context

What is the issue that we're seeing that is motivating this decision or change.

View keybase.md

Keybase proof

I hereby claim:

  • I am tobyhede on github.
  • I am tobyhede (https://keybase.io/tobyhede) on keybase.
  • I have a public key whose fingerprint is 9AA8 2B2E D31F EC90 2F24 7373 0678 0493 F70A EDB6

To claim this, I am signing this object:

@tobyhede
tobyhede / generate_tseries.sql
Created Jun 25, 2016
Easily generate timeseries data in PostgreSQL
View generate_tseries.sql
CREATE TABLE tseries AS
SELECT ts, (random()*9999)::int as count from generate_series(
'2015-01-01'::timestamptz,
'2016-06-01'::timestamptz,
'1 sec'::interval
) date;
@tobyhede
tobyhede / tap.rb
Last active Jan 2, 2016
To tap or not to tap ...
View tap.rb
#assuming a method returning an account
Account.where(email: email).first_or_create.tap do |account|
account.update_attributes!(name: name, login: login, image: image)
end
account = Account.where(email: email).first_or_create
account.update_attributes!(name: name, login: login, image: image)
account
View To Tap or Not To Tap.rb
app.users.find_by!(:identifier => identifier).tap do |user|
user.verify!
end
user = app.users.find_by!(:identifier => identifier)
user.verify!
user
@tobyhede
tobyhede / gist:5914924
Created Jul 3, 2013
Coffeescript super argument ordering. See the snake.
View gist:5914924
class Animal
constructor: (@name) ->
move: (meters, direction = "north") ->
console.log @name + " moved #{direction} #{meters}m."
class Snake extends Animal
move: (direction = "south", meters = 5) ->
console.log "Slithering..."
super meters, direction
@tobyhede
tobyhede / gist:5753979
Created Jun 11, 2013
vagrant chef reset
View gist:5753979
#!/bin/zsh
/usr/bin/vagrant destroy --force
yes | knife client delete {NODE_NAME}
yes | knife node delete {NODE_NAME}
/usr/bin/vagrant up
knife bootstrap localhost --node-name {NODE_NAME} --ssh-user vagrant --ssh-password vagrant --ssh-port 2222 --sudo
/usr/bin/vagrant provision
@tobyhede
tobyhede / gist:5562556
Created May 12, 2013
STDOUT: STDERR: update-rc.d: /etc/init.d/postgresql-9.2: file does not exist
View gist:5562556
Recipe: postgresql::server_debian
* package[postgresql-9.2] action install[2013-05-12T07:44:03+02:00] INFO: Processing package[postgresql-9.2] action install (postgresql::server_debian line 26)
[2013-05-12T07:44:03+02:00] DEBUG: package[postgresql-9.2] checking package status for postgresql-9.2
postgresql-9.2:
Installed: 9.2.4-0ppa1~lucid
Candidate: 9.2.4-0ppa1~lucid
Version table:
*** 9.2.4-0ppa1~lucid 0
500 http://ppa.launchpad.net/pitti/postgresql/ubuntu/ lucid/main Packages
100 /var/lib/dpkg/status
You can’t perform that action at this time.