Skip to content

Instantly share code, notes, and snippets.

@dsaiztc
dsaiztc / queries.sql
Last active July 2, 2019 15:51 — forked from iconara/queries.sql
Low level Redshift cheat sheet
-- Table information like sortkeys, unsorted percentage
-- see http://docs.aws.amazon.com/redshift/latest/dg/r_SVV_TABLE_INFO.html
SELECT * FROM svv_table_info;
-- Table sizes in GB
SELECT t.name, COUNT(tbl) / 1000.0 AS gb
FROM (
SELECT DISTINCT datname, id, name
FROM stv_tbl_perm
JOIN pg_database ON pg_database.oid = db_id
START TRANSACTION ;
ALTER TABLE schema_name.table_name RENAME TO table_name_old;
CREATE TABLE schema_name.table_name_new
-- Creation statement
;
INSERT INTO schema_name.table_name_new (
SELECT

One thing you can do from the command line is activate the virtual environment then install the kernel specification from within the environment:

python -m ipykernel install --user --name some-env --display-name "Python (some-env)"
ipython kernelspec list
@dsaiztc
dsaiztc / Haversine distance.java
Last active January 21, 2019 09:11
Calculate distance between two GPS points.
/**
* Calculate distance between two gps points based in Haversine formula: http://en.wikipedia.org/wiki/Haversine_formula
*
* @param latitude1 GPS point 1 Latitude
* @param longitude1 GPS point 1 Longitude
* @param latitude2 GPS point 2 Latitude
* @param longitude2 GPS point 1 Longitude
* @return Distance in kilometers (km)
*/
static double haversineDistance(float latitude1, float longitude1, float latitude2, float longitude2)
pipenv install cython
pipenv install git+https://github.com/jswhit/pyproj.git#egg=pyproj
@dsaiztc
dsaiztc / scp-cheatsheet.md
Created November 8, 2018 17:56 — forked from dehamzah/scp-cheatsheet.md
SCP Cheatsheet

Basic Syntax

$ scp source_file_path destination_file_path

Uploading

Single file

import ipaddress
for host in ipaddress.ip_network('204.93.240.0/24').hosts():
print(host)
SELECT TRIM(pgn.nspname) AS SCHEMA,
TRIM(a.name) AS TABLE,
id AS TableId,
decode(pgc.reldiststyle,
0, 'EVEN',
1,det.distkey ,
8,'ALL'
) AS DistKey,
decode(pgc.reldiststyle,
8,NULL,
@dsaiztc
dsaiztc / pwd.py
Last active September 6, 2018 08:06
import string
import random
chars = string.ascii_letters + string.digits + string.punctuation
chars = string.ascii_letters + string.digits
pwd_length = 16
''.join((random.choice(chars)) for x in range(pwd_length))
cursor = None
rows = []
total_rows = -1
while(True):
try:
total_rows += 1
row = next(cursor)
rows.append(row)
except bson.errors.InvalidBSON:
logger.exception('Failed to parse document')