Skip to content

Instantly share code, notes, and snippets.

View nad2000's full-sized avatar
🇳🇿
Working from New Zealand

Radomirs Cirskis nad2000

🇳🇿
Working from New Zealand
View GitHub Profile
@nad2000
nad2000 / radom_string.sh
Created September 24, 2013 04:20
Random string
head -1 /dev/urandom | base64 -w0
@nad2000
nad2000 / queries4juan.sql
Last active December 22, 2015 23:39
PostgreSQL queries for various present time series views The last query is an example of using window function over whole range (w/o PARTITION BY) with ORDER BY for creating a running total.
-- // How many events were created from date A to date B (possibly presenting data on a daily, weekly and monthly basis)
-- Replace 'week' with 'day' or 'month'
-- date_trunc takes: minute hour day week month quarter year
-- NB! TIMESTAMP '2013-09-16' == '2013-09-16 00:00:00' so BETWEEN includes only tickets sold until that date.
SELECT date_trunc('week', created_at) AS dt, count(*) AS total_events
FROM events
WHERE created_at BETWEEN TIMESTAMP '2013-06-16' AND TIMESTAMP '2013-09-16'
GROUP BY date_trunc('week', created_at)
-- // How many paid tickets were sold form date A to date B (presenting graphs on a day to day basis, weekly and monthly)
@nad2000
nad2000 / argumentor.py
Last active December 22, 2015 19:29 — forked from Ed-von-Schleck/gist:6391140
Back ported to 2.7 (it should work with earlier versions with added argparse)
import argparse
import inspect
class Argumentor:
def __init__(self, description=None):
self._parser = argparse.ArgumentParser(description=description)
self._subparsers = self._parser.add_subparsers()
def add(self, description={}):
@nad2000
nad2000 / run_sql_script.sh
Last active December 22, 2015 06:29
One-liner loops through a PostgreSQL DB list and executes on each of them a script
for db in $(psql -t -X -h 192.168.132.111 -U postgres -d probedb -c 'SELECT erfstore_id FROM erfstores') ; do psql -X -h 192.168.132.111 -U postgres -d $db -f /build/trunk/dock/tree/customer/endace/src/bin/dbmgr/scripts/erfstoredb/da_breakdown_summary_sql.sql ; done
# Or slightly more readable:
export PGHOST=fin7000-4
export PGDATABASE=probedb
export PGUSER=postgres
cd /ginkgo/trunk/ginkgo/tree/customer/endace/src/bin/dbmgr/scripts/erfstoredb/
for db in $(psql -t -X -c 'SELECT erfstore_id FROM erfstores') erfstoredb ; do psql -X -d $db -f da_breakdown_summary_sql.sql ; done
@nad2000
nad2000 / lfs.sh
Last active March 11, 2016 08:35
Building LFS (http://www.linuxfromscratch.org/) on a Ubuntu 12.04.2 LTS based on Linux From Scratch - Version 7.4
# Creating the $LFS directory
...
# Create lfs user and the profile for it
...
sudo su - lfs
# Downloading packet source:
mkdir -vp $LFS/sources
@nad2000
nad2000 / untar a bunch
Created August 29, 2013 03:22
To untar all tar files in one go
ls -1 *tar* | xargs -P 8 -I{} tar xf {}
@nad2000
nad2000 / delete.sh
Created August 1, 2013 02:47
simple way of deleting particular lines from a text file with ed and sed.
# with sed:
sed -i '28d' ~/.ssh/known_hosts
# with ed:
ed -s ~/.ssh/known_hosts <<< $'28d\nw'
@nad2000
nad2000 / edit_tsv.sh
Created June 29, 2013 08:26
remove DOS line ends (DOS to UNIX) and add the missing field to TAB separated file (TSV)
LANG=ko_KO.UTF-8 sed 's/\r$//; s/^\([^\t]*\)\t\([^\t]*\)$/\1\t\2\t/' set2.csv > set2_.csv
@nad2000
nad2000 / gist:5746324
Created June 10, 2013 03:20
applications of sed and awk to analyze inodes
# total storage size held by processes:
lsof /data | grep postgres | grep deleted | awk '{ SUM += $7} END {print SUM}'
# processes that hold inodes:
lsof /data -u postgres | grep "(deleted)" | tr -s ' ' | cut -d ' ' -f2 | sort -u | xargs ps -u -p
@nad2000
nad2000 / max_flow_counts.r
Created June 9, 2013 02:14
Max flow count distgribution
# install.packages("RPostgreSQL")
# install.packages("zoo")
# Notes: EMA - Exponential moving average with alpha=0.05
library(RPostgreSQL)
library(TTR)
drv <- dbDriver("PostgreSQL")
##con <- dbConnect(drv, dbname="probedb", user="postgres", host="192.168.132.111")
con <- dbConnect(drv, dbname="1", user="postgres", host="192.168.132.111")