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 / gist:5705543
Last active December 18, 2015 01:39 — forked from anonymous/gist:5705535
# Include the Dropbox SDK libraries
from dropbox import client, rest, session
# Get your app key and secret from the Dropbox developer website
APP_KEY = 'KEYKEYKEY'
APP_SECRET = 'SECRET'
# ACCESS_TYPE should be 'dropbox' or 'app_folder' as configured for your app
ACCESS_TYPE = 'dropbox' ### 'app_folder'
def straddr2int(addr):
"""
converts IPv4 address inot an integer
>>> str2int('192.168.129.43')
3232268587
"""
return reduce( lambda a,b: a<<8|b, map(int,addr.split('.')) )
@nad2000
nad2000 / flow_counts.r
Last active December 18, 2015 06:08
flow count with exponential moving average data comes from Postgres DB
# 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")
@nad2000
nad2000 / fsvsbs.r
Created June 9, 2013 02:11
Relative Error of Bandwidth Estimate Based On Flow Sample
fsvsbs <- read.csv("~/fsvsbs.csv", sep=";")
fsvsbs$rel_err = fsvsbs$rel_err*100
plot(
fsvsbs$rel_err ~ fsvsbs$delta,
xlab="Step / Sub-range Length (sec)",
ylab="Relative Error (%)",
main="Relative Error of Bandwidth Estimate Based On Flow Sample")
nls_fit <- nls(rel_err ~ a + b * delta^(-c), fsvsbs, start = list(a = 43, b = 4, c = 0.2))
lines(fsvsbs$delta, predict(nls_fit), col="red",lwd=3)
@nad2000
nad2000 / gaps.r
Created June 9, 2013 02:12
Distribution of sample counts per gap value between the current sample and the previous one
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="6", user="postgres", host="192.168.132.111")
# dbListConnections(drv)
# dbGetInfo(drv)
# summary(con)
rs <- dbSendQuery(con,"
SELECT
delta, delta_cnt ,
@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")
@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 / 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 / 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 / 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 {}