Skip to content

Instantly share code, notes, and snippets.

This file has been truncated, but you can view the full file.
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.3.0
-- Dumped by pg_dump version 9.3.0
-- Started on 2015-02-11 14:16:22
SET statement_timeout = 0;
SET lock_timeout = 0;
@rhysallister
rhysallister / gist:af1ff68b37b7060ea4f9
Created February 14, 2015 22:53
list columns in a table for postgres
SELECT attrelid::regclass, attnum, attname
FROM pg_attribute
WHERE attrelid = 'gn.primaryline'::regclass
AND attnum > 0
AND NOT attisdropped
ORDER BY attnum;
@rhysallister
rhysallister / averages.txt
Created March 13, 2015 03:03
cricket above 40 avg
Player Span Mat Inns NO Runs HS AveDescending BF SR 100 50 0 true avg delta 50+ every
HM Amla (SA) 2008-2015 113 110 9 5666 159 56.09 6293 90.03 20 28 2 51.51 4.58 2.291666667
MG Bevan (Aus) 1994-2004 232 196 67 6912 108* 53.58 9320 74.16 6 46 5 35.27 18.31 3.769230769
AB de Villiers (Afr/SA) 2005-2015 185 178 30 7876 162* 53.21 7966 98.87 20 45 6 44.25 8.96 2.738461538
V Kohli (India) 2008-2015 155 147 23 6495 183 52.37 7216 90 22 33 10 44.18 8.19 2.672727273
MS Dhoni (Asia/India) 2004-2015 259 225 65 8343 183* 52.14 9379 88.95 9 56 7 37.08 15.06 3.461538462
IJL Trott (Eng) 2009-2013 68 65 10 2819 137 51.25 3658 77.06 4 22 5 43.37 7.88 2.5
MEK Hussey (Aus) 2004-2012 185 157 44 5442 109* 48.15 6243 87.16 3 39 3 34.66 13.49 3.738095238
Zaheer Abbas (Pak) 1974-1985 62 60 6 2572 123 47.62 3033 84.8 7 13 2 42.87 4.75 3
KS Williamson (NZ) 2010-2015 71 65 9 2634 145* 47.03 3181 82.8 6 16 4 40.52 6.51 2.954545455
create table streetlightaudit._migis2 as
-- update streetlightaudit.complete_streetlights
-- set geom = st_setsrid(geom,3448);
-- update streetlightaudit.mlgd_streetlamp
-- set geom = st_setsrid(geom,3448);
with one as (
select aa.id, aa.geom from streetlightaudit.complete_streetlights aa
left join streetlightaudit.mlgd_streetlamp bb on st_intersects(aa.geom,bb.geom)
where bb.id is null
)

Magic words:

psql -U postgres

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

  • \q: Quit/Exit
  • \c __database__: Connect to a database
  • \d __table__: Show table definition including triggers
@rhysallister
rhysallister / riot-ajax.tag
Created August 25, 2015 19:46
riot ajax tag
<rg-ajax>
<script type="coffeescript">
@.on('mount', ->
req = new XMLHttpRequest()
req.open(opts.verb,opts.url, opts.async)
req.onload = ->
if req.status is 200
@rhysallister
rhysallister / gist:282fb67218702c69b825
Last active October 22, 2015 23:43
python3, bottle.py (specifically simple template engine) in postgres 9.4
CREATE OR REPLACE FUNCTION _.lw__customer_list(in inj json)
RETURNS text AS
$BODY$
import json
from bottle import template
ff = json.loads(inj)
qq = template("""<h2>Customer Count: {{len(cc)}}</h2>""",cc=ff)
@rhysallister
rhysallister / metpull.py
Created November 1, 2015 18:55
Pull imagery from the met services site
import requests
import os
met_office_url = 'http://jamaica.weatherproof.fi/web/radar_180.php'
q = requests.get(met_office_url)
for line in q.text.split('\n'):
if line.split('=')[0] == 'var anim_timestamps ':
image_list = (line.split('(')[1][:-2]).split(',')
image_list = [image.strip('"') for image in image_list]
if line.split('=')[0] == 'var anim_images_weather_weather ':
@rhysallister
rhysallister / 4day_xmas_weekend.sql
Created December 24, 2015 19:26
List number of years out of the next 100 years where Christmas & Boxing day fall on a Thursday & Friday thus giving a lovely 4 day weekend
with days as (
select generate_series(now(), (now() + '100 years'::interval),'1 day'::interval)::date theday
)
select extract(year from theday) from days
where
(extract(DOW from theday) = 4 and theday::text like '%-12-25')
or
(extract(DOW from theday) = 5 and theday::text like '%-12-26')
group by extract(year from theday)
@rhysallister
rhysallister / euler_0001.sql
Last active January 6, 2016 19:32
Project euler in sql
select sum(g) from (
select generate_series(3,2e6 - 1,3) g
union all
select generate_series(5,2e6 - 1,5) g
) as foo;