This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Collect data until ^C: | |
while true ; do df /data ; sleep 1 ; done | tee storage.txt | |
# Extract "Used field": | |
grep /dev/md0 storage.txt | sed 's/ */\t/g' | cut -f4 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. download and install PostgreSQL 9.3 (remember the password your entered) | |
# 2. install PostGIS using Stackbuilder (it's a part of PostgreSQL 9.3 installation) | |
# Make sure postgeres is started | |
# Run script that fix issues with choice_web: | |
psql -U postgres -d postgres -f choice_web_migr.sql | |
# Load the dump (that might take upto 10min): | |
psql -U postgres -f choice_web_02_21_2014.dump -d choice_web 2>choice_web_log.err |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo 'task goes here' | cat - todo.txt > temp && mv temp todo.txt | |
# OR | |
cat <(echo "task goes here") todo.txt > todo_new.txt | |
# OR | |
echo -e "task goes here\n$(cat todo.txt)" > todo.txt | |
# OR | |
sed -i '1s/^/task goes here\n/' todo.txt | |
# OR | |
sed -i '1itask goes here' todo.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(n): | |
if n <= 2: | |
return 1 | |
else: | |
return fib(n-1) + fib(n-2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# drops first portion of a path $1 if length is greater than $2 | |
function __droppath { | |
if [[ ${#1} -gt $2 ]]; then | |
p=$1 | |
while [ ${#p} -gt $2 ]; do | |
p="/"$(echo "$p"|cut -d"/" -f3-) | |
done | |
echo "..."$p | |
else | |
echo $1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
egrep "(\*\*\*\*|excluding)" test.log | sed '/tps/ s/tps = \([.0-9]*\) .*/\1/; /uview/ s/ uview\([0-9]*\)/\1/' | sed -n '/\**/ {N;s/\n/,/;N;s/\n/,/;s/\**//p}' | |
## With loading into PostgreSQL: | |
# Create table: | |
psql -d 5 -c "create table test_output( id int, tps1 numeric, tps2 numeric)" | |
# Extract and load data: | |
egrep "(\*\*\*\*|excluding)" test.log | sed '/tps/ s/tps = \([.0-9]*\) .*/\1/; /uview/ s/ uview\([0-9]*\)/\1/' | sed -n '/\**/ {N;s/\n/,/;N;s/\n/,/;s/\**//p}' | psql -d 5 -c "TRUNCATE TABLE test_output; COPY test_output FROM STDIN (FORMAT csv, DELIMITER ',', HEADER false)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- PostgreSQL | |
DROP TABLE IF EXISTS uview5_uni; | |
CREATE TABLE uview5_uni AS | |
SELECT | |
start_time, | |
CASE e WHEN 1 THEN mac_addr_1 ELSE mac_addr_2 END src_mac_addr, | |
CASE e WHEN 1 THEN mac_addr_2 ELSE mac_addr_1 END des_mac_addr, | |
CASE e WHEN 1 THEN byte_count_1 ELSE byte_count_2 END byte_count, | |
CASE e WHEN 1 THEN packet_count_1 ELSE packet_count_2 END packet_count, | |
last_time, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% DATA IMPORTING AND VISUALIZATION | |
from urllib2 import urlopen | |
from contextlib import closing | |
from os.path import basename | |
def download_file(url, name=None): | |
with closing(urlopen(url)) as u, open(name if name else basename(url), 'w') as f: | |
f.write(u.read()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Original from: | |
# http://pyvideo.org/video/1780/transforming-code-into-beautiful-idiomatic-python | |
colors = ['red', 'green', 'blue', 'yellow'] | |
names = ['apple', 'carrot', 'melon'] | |
for color in reversed(colors): | |
print color |