Skip to content

Instantly share code, notes, and snippets.

@cosmin
cosmin / inject.py
Created January 6, 2014 05:59
Function to create a new class using a base class with substituted global scope
import types
def clone(original, **newg):
return types.FunctionType(original.func_code,
dict(original.func_globals, **newg),
original.func_name,
original.func_defaults,
original.func_closure)
def inject(cls, **newg):
#!/bin/bash
#
# wlsadmin startup script for admin server
#
# chkconfig: - 75 15
# description: WebLogic Admin Server
# processname: WLSADMIN
# Source function library
. /etc/rc.d/init.d/functions
@cosmin
cosmin / make-app.sh
Created May 19, 2013 02:43
Create site specific apps using Google Chrome
#!/bin/sh
echo "What should the Application be called (no spaces allowed e.g. GCal)?"
read inputline
name=$inputline
echo "What is the url (e.g. https://www.google.com/calendar/render)?"
read inputline
url=$inputline
@cosmin
cosmin / cisco-crypt.py
Created May 19, 2013 02:41
decode Cisco VPN group passwords
import base64
try:
from hashlib import sha1
except ImportError:
from sha1 import new as sha1
import random
import struct
import Crypto.Cipher.DES3 as DES3
def decrypt_password(data):
#ifndef OBJC_ARC_ENABLED
#ifdef __has_feature
#define OBJC_ARC_ENABLED __has_feature(objc_arc)
#else
#define OBJC_ARC_ENABLED 0
#endif
#endif
@cosmin
cosmin / gist:3083363
Created July 10, 2012 13:52
Reveal desktop
tell application "Finder"
reveal Desktop
activate
end tell
(in-ns 'user)
;;; for convenience, code from clojure.contrib.combinatorics
(defn- index-combinations
[n cnt]
(lazy-seq
(let [c (vec (cons nil (for [j (range 1 (inc n))] (+ j cnt (- (inc n)))))),
iter-comb
(fn iter-comb [c j]
@cosmin
cosmin / daterange.py
Created August 12, 2011 16:01
range equivalent for datetime
import datetime
def daterange(start_or_end, end=None, step=datetime.timedelta(1)):
"daterange([start,] stop[, step]) -> list of dates"
if end == None:
end = start_or_end
start = datetime.date.today()
current = start
while current < end:
yield current
@cosmin
cosmin / processhar.py
Created April 26, 2011 11:55
Extract images, css and js from a HAR archive
#!/usr/bin/env python
import sys
import json
def process(filename):
inp = open(filename, 'r')
data = json.load(inp)
inp.close()
entries = [x['request']['url'] for x in data['log']['entries']]
@cosmin
cosmin / camelcase_to_filename.py
Created April 26, 2011 11:55
Example for turning a camelcase name into a _ separated filename.
def main(filename):
data = open(filename).read()
for char in range(65,91):
letter = chr(char)
data = data.replace(letter, '_' + letter.lower())
print data[1:].replace('\n_','\n').replace('_test','_test.rb')