This file contains 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
from sqlalchemy.ext.declarative import declarative_base | |
""" | |
This gist demonstrates ways to retrieve foreign keys in an SQLAlchemy database schema. | |
""" | |
Base = declarative_base() | |
metadata = Base.metadata | |
# then you must populate schema |
This file contains 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
#! /bin/bash | |
#log memory each minute | |
while true; do | |
dt=`date` | |
mem=`cat /proc/meminfo | grep -E "MemFree"` | |
mem2=`cat /proc/meminfo | grep -E "MemAvailable"` | |
echo -e "$dt \t $mem \t $mem2" | tee -a memlog.txt | |
sleep 60 | |
done |
This file contains 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
""" | |
This contains various implementations of SQL functions in python | |
The two functions are not built for the same context | |
""" | |
def hash_join(table1, index1, table2, index2): | |
""" | |
Perform a sql like join operation on two dicts, on the specified indexes | |
""" | |
from collections import defaultdict |
This file contains 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
# this is just a dirty hack to play an mp3 over a network, need netcat and mplayer | |
# on the sending machine (replace localhost with ip): | |
nc localhost 1234 < x.mp3 | |
# on the playing machine: | |
nc -l -p 1234 | mplayer - |
This file contains 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
# this will fill a disk to 5TB with one command, accounting for existing disk usage | |
# $a will be in kilobytes, so it must be converted in the expr to units of 150MB | |
# bs is set for efficiency, results on your disk may vary, if you change this, you'll need to change the number at the end in expr (currently 1024 * 150) | |
# the sed command specifies line 9 of the output pulled from df -k, you will need to change for your df output | |
dd if=/dev/zero of=/mnt/partition/bigfile bs=150MB count=$(let "a = 5368709120-`df -k | awk '{ print $3 "\t" }' | sed -n '9p'`"; expr $a / 153600) |
This file contains 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
# this is a work in progress notepad, will include pdftk and ghostscript stuff | |
# replace page 13 of doc1.pdf with doc2.pdf | |
pdftk A=doc1.pdf B=doc2.pdf cat A1-12 B1 A14-end output out1.pdf | |
# remove the first 4 pages from in.pdf | |
pdftk A=in.pdf cat A5-end output out.pdf | |
# use ghostscript to combine PDFs | |
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=finished.pdf file1.pdf file2.pdf file3.pdf |
This file contains 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
#! /usr/bin/env python3 | |
# | |
# Σ i | |
# i=s | |
from functools import reduce | |
# the sequence to sum, you can use range(blah) as well | |
s = [1, 2, 3, 5] |
This file contains 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
# truncate num_bytes off the end of a file | |
import os | |
def trunc(filename, num_bytes): | |
with open(filename, 'rb+') as fi: | |
fi.seek(-1 * num_bytes, os.SEEK_END) | |
fi.truncate() |
This file contains 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
sudo apt-get install calibre | |
ebook-convert book.epub book.mobi |
This file contains 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
0.0.0.0 www.example.com | |
0.0.0.0 example.com | |
::0 www.example.com | |
::0 example.com |