Skip to content

Instantly share code, notes, and snippets.

View booo's full-sized avatar

Philipp Borgers booo

View GitHub Profile
21 May 03:38:59 - info: Loading genesis block
21 May 03:38:59 - info: Connecting to peer localhost:8333
21 May 03:38:59 - info: Connection refused for localhost:8333
21 May 03:38:59 - info: IRC Bootstrap found 14 peers
21 May 03:39:04 - info: Connecting to peer 142.244.185.198:18333
21 May 03:39:04 - info: Connecting to peer 67.82.96.109:18333
21 May 03:39:04 - info: Connecting to peer 81.141.76.31:18333
21 May 03:39:04 - info: Connecting to peer 178.18.90.41:18333
21 May 03:39:04 - info: Connecting to peer 66.9.24.5:18333
21 May 03:39:04 - info: Connecting to peer 109.239.89.147:18333
var url = require("url");
function parseConnectionString(str) {
var result = url.parse(str);
result.host = result.hostname;
result.database = result.pathname ? result.pathname.slice(1) : null;
var auth = (result.auth || ':').split(':');
result.user = auth[0];
result.password = auth[1];
return result;
@booo
booo / gist:1115556
Created July 30, 2011 14:01
average over the tags per node (osm)
SELECT avg(tagspernode) FROM (SELECT id, count(tags) AS tagsPerNode FROM (SELECT each(tags) as tags, id FROM nodes) AS tuples GROU LIMIT 10000) BY id) AS foo;
@booo
booo / gist:1115871
Created July 30, 2011 19:10
sort on the value of an hstore
SELECT id, tags->'amenity' AS value, tags FROM nodes WHERE tags ? 'amenity' ORDER BY tags->'amenity';
@booo
booo / gist:1123510
Created August 3, 2011 19:09
special insert for postgres
--does not work...
CREATE OR REPLACE FUNCTION myinsert(tablename text, g geometry, s hstore) RETURNS integer AS $$
DECLARE i integer;
DECLARE sequencename text;
DECLARE sql text;
BEGIN
sequencename = tablename || '_sequence_id';
i = nextval(sequencename);
sql = 'INSERT INTO ' || tablename || '(id, geom, store) VALUES ('|| i ||', '|| g ||','|| s ||');';
EXECUTE sql;
@booo
booo / gist:1137489
Created August 10, 2011 17:17
stupid pg test
pg = require "pg"
pg.connect "pg://postgres:secret@localhost:5432/testing", (error, client) ->
if error
console.log error
else
query = "SELECT NOW() AS when;"
client.query query, (error, result) ->
if error then console.log error
else console.log result
@booo
booo / hs_2json.sql
Created August 26, 2011 14:24 — forked from kashif/hs_2json.sql
hstore to json function from Ilya Kosmodemiansky
CREATE FUNCTION public.hs_2json(hs hstore) RETURNS text AS $$
DECLARE
rv text;
r record;
BEGIN
rv:='';
for r in (select key, val from each(hs) as h(key, val)) loop
if rv<>'' then
rv:=rv||',';
end if;
@booo
booo / redis_error.coffee
Created August 31, 2011 10:32
redis error handling
pg = require "pg"
http = require "http"
redis = require "redis"
rclient = redis.createClient()
rclient.on "error", (error) ->
console.log error
(http.createServer (req, res) ->
pg = require "pg"
http = require "http"
s = "postgres://postgres:testing@localhost:5432/testing"
(http.createServer (req, res) ->
pg.connect s, (error, client) ->
if error
console.log error
else
git = require "nodegit"
git.repo "bla/.git", (error, repo) ->
if error then console.log error
else
repo.branch "master", (error, branch) ->
if error then console.log error
else
history = branch.history()
history.on "commit", (index, commit) ->