Skip to content

Instantly share code, notes, and snippets.

@cosmin
cosmin / aws.credentials
Created April 18, 2011 04:00
Script to setup AWS credentials for various command line tools
AWSAccessKeyId=YOUR_AWS_ACCESS_KEY
AWSSecretKey=YOUR_AWS_SECRET_KEY
@cosmin
cosmin / rsakeyfingerprint.py
Created February 27, 2011 22:12
Utilities for fingerprinting RSA keys
import base64
from hashlib import sha1, md5
import re
from pyasn1.codec.ber import encoder
from pyasn1.type.univ import *
def rsa_key_to_der(key):
seq = Sequence()
@cosmin
cosmin / uniq_fields_with_count.awk
Created January 16, 2011 15:20
print only lines with unique fields, keep track of count
#one-liner awk 'NR == 1 {lastfield = $1; matchline = $0; count = 1; next} {if (lastfield != $1) {print count " " matchline; count = 0; matchline=$0; } count += 1; lastfield = $1} END {print count " " matchline}' inp.txt
NR == 1 {
lastfield = $1;
matchline = $0;
count = 1;
next
}
{
@cosmin
cosmin / sendit.py
Created January 9, 2011 19:40
Easily send an email attachment from the command line
import os, sys
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import formatdate
from email import Encoders
SMTP_SERVER='localhost'
require("clicks-in-new-buffer.js");
clicks_in_new_buffer_target = OPEN_NEW_WINDOW;
url_completion_use_history = true;
url_completion_use_bookmarks = false;
can_kill_last_buffer = false;
download_buffer_automatic_open_target = OPEN_NEW_BUFFER_BACKGROUND;
interactive("instapaper", "Add current page to instapaper",
function(I) {
# saner syntax for optparse add_option
import os
def make_option_maker(parser, cmdline_prefix="", env_prefix="", dest_prefix=""):
"""Return a function that can be used to add_option with saner syntax.
Arguments:
parser: the parser object that will be used by the returned function
cmdline_prefix: will be used together with the name to build the command
# tzdate - helper functions for using timezones from dateutil. utcnow and localnow.
import datetime
from dateutil import tz
UTC_TZ = tz.gettz('UTC')
LOCAL_TZ = tz.gettz()
def utcnow():
return datetime.datetime.now(UTC_TZ)
find . -name '*.txt' | grep surefire | xargs grep "Time elapsed: $REGEX" | sed -e 's%^./\([^/]*\)/target/surefire-reports/%\1 => %' -e 's/.txt://' -e 's/\(.*\)Tests run.*Time elapsed:\(.*\)/\2 => \1/' | sort -r | awk '{sum+= $1 } {if ($1 >= 1) slow+= $1} {if ($1 >= 1) print $0} END {print "\nTotal time in slow tests = " slow " sec"} END {print "Total time in all tests = " sum " sec"} END {print "Ratio = " slow/sum};'
# Apple script
# from http://www.macosxhints.com/article.php?story=20070525090946356
set talkTRIES to 0
set TRYCOUNT to 250
# you might need to run sudo touch /private/var/db/.AccessibilityAPIEnabled
# to enable Accessibility API for AppleScript
tell application "System Preferences"