Skip to content

Instantly share code, notes, and snippets.

@tokumine
tokumine / n-tile.sql
Created January 9, 2012 15:23
calculating equal frequency buckets, or n-tile ranges in postgresql
-- To calculate flexible quantile ranges in postgresql, for example to calculate n equal
-- frequency buckets for your data for use in a visualisation (such as binning for a
-- choropleth map), you can use the following SQL:
-- this functions returns 6 equal frequency bucket ranges for my_column.
SELECT ntile, avg(my_column) AS avgAmount, max(my_column) AS maxAmount, min(my_column) AS minAmount
FROM (SELECT my_column, ntile(6) OVER (ORDER BY my_column) AS ntile FROM my_table) x
GROUP BY ntile ORDER BY ntile
-- more on the ntile() function and windowing here:
@jstrachan
jstrachan / gist:f960917b4861f30a8a45
Last active August 29, 2015 14:02
names your iTerm2 tab after the current working directory, shows the path in the prompt and the git branch
# thanks to this gist for the iTerm2 tab naming stuff: https://gist.github.com/phette23/5270658
# can't remember where I cribbed the rest of this from!
# hacked it a bit to work on OS X
_bold=$(tput bold)
_normal=$(tput sgr0)
__vcs_dir() {
local vcs base_dir sub_dir ref
sub_dir() {
@probonopd
probonopd / F1E200.md
Last active June 30, 2024 18:12
Allwinner F1E200 electronic postcard with USB Device ID 1f3a:1000

USB Device ID 1f3a:1000 Allwinner F1E200 electronic postcard

I received a promotional folder that plays a video with sound when opening the folder. This contains a rechargeable LiPo battery, a TFT display, a speaker, a power switch, a push button, 256 MB flash memory, RAM, and a CPU.

All of this for watching one 1-minute video.

What a waste! Certainly not environmentally friedndly. Until repurposed creatively!

On the back it says that the product can be sent back to the manufacturer for free recycling. Still I was wondering if I could do more with it.

@ereli
ereli / countries.sql
Last active June 6, 2024 14:22 — forked from adhipg/countries.sql
Sql dump of all the Countries, Country Codes, Phone codes. PostgreSQL compatible
CREATE SEQUENCE country_seq;
CREATE TABLE IF NOT EXISTS country (
id int NOT NULL DEFAULT NEXTVAL ('country_seq'),
iso char(2) NOT NULL,
name varchar(80) NOT NULL,
nicename varchar(80) NOT NULL,
iso3 char(3) DEFAULT NULL,
numcode smallint DEFAULT NULL,
phonecode int NOT NULL,
@rikka0w0
rikka0w0 / sunxi_fel.md
Last active May 10, 2022 01:29
sunxi_fel.md