Skip to content

Instantly share code, notes, and snippets.

View marklit's full-sized avatar

Mark Litwintschik marklit

View GitHub Profile
@marklit
marklit / .psqlrc
Created October 28, 2015 08:25
Postgres psql customisations
\set PROMPT1 '%[%033[1;33m%]%M:%>%[%033[1;32m%] %n@%/%R%[%033[0m%]%# '
\set PROMPT2 ' %R > '
\x auto
\timing
\set HISTFILE ~/.psql_history- :DBNAME
\set HISTCONTROL ignoredups
\set COMP_KEYWORD_CASE upper
\pset null '¤'
// See: https://imgur.com/gafDVW5
package com.example.mark.myapplication;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
// See: https://imgur.com/6o6DP4Q
package com.example.mark.myapplication;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
@marklit
marklit / brin.sql
Last active August 20, 2018 03:56
Postgres 9.5 on Ubuntu 15
-- From: http://michael.otacoo.com/postgresql-2/postgres-9-5-feature-highlight-brin-indexes/
CREATE TABLE brin_example AS SELECT generate_series(1,100000000) AS id;
CREATE INDEX btree_index ON brin_example(id);
-- By default, the block size is 128 pages. This resolution can be increased or decreased using the pages_per_range
CREATE INDEX brin_index ON brin_example USING brin(id);
CREATE INDEX brin_index_64 ON brin_example USING brin(id) WITH (pages_per_range = 64);
CREATE INDEX brin_index_256 ON brin_example USING brin(id) WITH (pages_per_range = 256);
CREATE INDEX brin_index_512 ON brin_example USING brin(id) WITH (pages_per_range = 512);
-- The lower the pages per block, the more space the index will occupy, but the less lossy the index will be, i.e. it will need to discard fewer rows.
@marklit
marklit / mappings.txt
Created April 8, 2016 14:19
Taxi Data Mapping w/ ES-compatible data types
trip_id integer
vendor_id string
pickup_datetime TIMESTAMP
dropoff_datetime TIMESTAMP
store_and_fwd_flag string
rate_code_id integer
pickup_longitude float
pickup_latitude float
dropoff_longitude float
dropoff_latitude float
@marklit
marklit / es-dsl.md
Created May 11, 2016 07:28
Elasticsearch DSL queries generated by SQL plugin

Query 1

SELECT cab_type,
       count(*)
FROM trips
GROUP BY cab_type
@marklit
marklit / sqlite3_insert.sh
Created May 18, 2016 20:21
Insert compressed CSV data into an SQLite3 table
$ (echo -e "PRAGMA synchronous=OFF; PRAGMA count_changes=OFF;\n.mode csv\n.separator ,\n.import /dev/stdin trips";
gunzip -c ~/taxi-data/*.csv.gz) | \
sqlite3 trips.db
@marklit
marklit / deep fizz buzz.md
Created September 24, 2016 13:58
Perfectly predicted Fizz buzz

See GitHub for the source code and TensorFlow on a GTX 1080 for installation notes.

$ python fizz_buzz.py \
    --hidden_units 500 \
    --iterations 4000 \
    --learning_rate 0.04
- Inexplicable perversity of human nature.
- The clever machinations of MongoDB's marketing people.
- The AGPL license killed it.
- We spent too long development before monetizing.
- Bad performance.
- Numeric types limited to a 64-bit `float`.
- Great product, but didn't/couldn't translate to revenue.
- Bad business model.
- Failure in timezones/timestamp nuances.
@marklit
marklit / _run.sh
Created February 25, 2017 19:51
CommonCrawl / AWS EMR / MRJob
git clone https://github.com/Smerity/cc-mrjob.git ~/cc-mrjob && cd ~/cc-mrjob
pip install -r requirements.txt
pip install awscli
aws configure
curl -O https://commoncrawl.s3.amazonaws.com/crawl-data/CC-MAIN-2017-04/wat.paths.gz
gunzip wat.paths.gz
python server_analysis.py \
-r emr \
--conf-path mrjob.conf \