Skip to content

Instantly share code, notes, and snippets.

import sys
def readfile(file):
with open(file) as src:
return [line.strip() for line in src.readlines()]
lines_1 = readfile(sys.argv[1]); lines_2 = readfile(sys.argv[2])
for line in lines_1:
if not line in lines_2:
@getadeo
getadeo / gist:b6a89bb90b5e8a01e21e
Created December 7, 2015 10:23 — forked from hest/gist:8798884
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
$ cat file.csv | tr "\\t" ","
setxkbmap -option ctrl:nocaps
@getadeo
getadeo / csv-remove-duplicates.md
Last active September 8, 2015 16:55
Check if it has duplicates in first column and remove row
$ date
$ more /etc/timezone
$ sudo dpkg-reconfigure-tzdata
$ /etc/init.d/cron stop
$ /etc/init.d/cron start
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$+=\-_()|~`#\{\}\[\].,:;<>\\\/"'^@$!%*?&])[A-Za-z\d$+=\-_()|~`#\{\}\[\].,:;<>\\\/"'^@$!%*?&][A-Za-z\d$+=\-_()|~`#\{\}\[\].,:;<>\\\/"'^@$!%*?&A-Za-z]{8,}
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$+=\-_()|~`#\{\}\[\].,:;<>\\\/"\'^@$!%*?&])[A-Za-z\d$+=\-_()|~`#\{\}\[\].,:;<>\\\/"\'^\@$!%*?&][A-Za-z\d$+=\-_()|~`#\{\}\[\].,:;<>\\\/"\'^@$!%*?&A-Za-z]{10,15}
import paramiko
k = paramiko.RSAKey.from_private_key_file("/Users/whatever/Downloads/mykey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "www.acme.com", username = "ubuntu", pkey = k )
print "connected"
commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ]
for command in commands:
print "Executing {}".format( command )
(function () {
function tConvert (time) {
// Check correct time format and split into components
time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
if (time.length > 1) { // If time format correct
time = time.slice (1); // Remove full string match value
time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM
time[0] = +time[0] % 12 || 12; // Adjust hours