Skip to content

Instantly share code, notes, and snippets.

@msakrejda
msakrejda / gist:2fd9435fd0a453063e9e
Created May 19, 2015 02:51
sequel association issue
[1] pry(main)> require 'sequel'
=> true
[2] pry(main)> DB = Sequel.connect('postgres:///maciek')
=> #<Sequel::Postgres::Database: "postgres:///maciek">
[3] pry(main)> DB.run <<-EOF
[3] pry(main)* CREATE TABLE a(id serial primary key);
[3] pry(main)* CREATE TABLE b(id serial primary key, a_id integer);
[3] pry(main)* EOF
=> nil
[4] pry(main)> class A < Sequel::Model(:a)
@msakrejda
msakrejda / gh-pull-with-prs.sh
Last active August 29, 2015 14:00
automagic GitHub pull requests as remote branches
#!/bin/bash
# automagically clone with https://help.github.com/articles/checking-out-pull-requests-locally
# since this is only going to work on GitHub anyway, don't make the user specify the full URL
usage="Usage: $0 user/repo"
path="${1:?$usage}"
repo="$(basename "$path")"

Keybase proof

I hereby claim:

  • I am deafbybeheading on github.
  • I am deafbybeheading (https://keybase.io/deafbybeheading) on keybase.
  • I have a public key whose fingerprint is 490A 435A 3129 AE3D 3A1D A4E6 EF6D F5EF C1E1 D6E0

To claim this, I am signing this object:

@msakrejda
msakrejda / gist:6806803
Last active December 24, 2015 13:39
go/crypto RSA key validation

Current version (20 iterations of ProbablyPrime):

$ go test -run none -bench=. -benchtime=60s
PASS
BenchmarkRSA2048Validate	    1000	 137668985 ns/op
...

Fewer (2) iterations of ProbablyPrime:

maciek=# select g as "2", 1.0 / g as "1" from generate_series(1, 3) g order by 2;
2 | 1
---+------------------------
3 | 0.33333333333333333333
2 | 0.50000000000000000000
1 | 1.00000000000000000000
(3 rows)
maciek=# select g as "2", 1.0 / g as "1" from generate_series(1, 3) g order by "2";
2 | 1
@msakrejda
msakrejda / WARN-on-bad-estimate
Created October 18, 2012 19:13
Warn when actual rows are significantly different than estimated rows in an EXPLAIN ANALYZE in postgres
postgres=# create table t(a integer); create index t_idx on t(a);
CREATE TABLE
CREATE INDEX
postgres=# insert into t select g from generate_series(1,10) g;
INSERT 0 10
postgres=# explain analyze select * from t where a > 8;
QUERY PLAN
-------------------------------------------------------------------------------------------
Seq Scan on t (cost=0.00..1.12 rows=2 width=4) (actual time=0.017..0.019 rows=2 loops=1)
Filter: (a > 8)
@msakrejda
msakrejda / catalog_state
Created October 4, 2012 15:09
Ballpark catalog state query
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
TEXT(c.reltuples) as "Info"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND n.nspname !~ '^pg_toast'
...
|
* commit f44a3580b2a382ec22e90dad5d35e446bcd1d72b
| Author: Marc G. Fournier <scrappy@hub.org>
| Date: Sun Nov 1 16:55:02 1998 +0000
|
| Remove various files that were moved to various subdirectories...
|
| Requested by: Peter T Mount peter@retep.org.uk
|