Skip to content

Instantly share code, notes, and snippets.

View rossdylan's full-sized avatar

Ross Delinger rossdylan

View GitHub Profile
"""
Module that wraps around ping and traceroute. The X version uses a new threading thingy
"""
import procThread
import threading
__info__ = {
"Author": "Ross Delinger",
"Version": "1.0",
"Dependencies": ["ping", "traceroute"]
}
"""
Used to run processes and keep the main module free to do other things.
Unfortunately this thread is designed to work under unix based systems so...
Sorry windows users :/
"""
import MODIFIED_subprocess as subProc
import os
import threading
class procThread(threading.Thread):
context = None
ERROR:Modules:Error running command ping
Traceback (most recent call last):
File "/Users/rossdelinger/Documents/Schongo/modules/__init__.py", line 491, in handle_command
cmdf(ctx, cmd, arg, *args)
File "/Users/rossdelinger/Documents/Schongo/modules/netcmdsX.py", line 17, in ping
pt = procThread(shellCmd, ctx)
TypeError: 'module' object is not callable
@rossdylan
rossdylan / SuperParamiko.py
Created June 22, 2012 18:22
pbs like functionality using paramiko
import paramiko
from functools import partial
class SuperParamiko(object):
"""
usage:
>> ssh = SuperParamiko("hostname", "username")
>> ssh.ls()
>> ssh.git("pull")
@rossdylan
rossdylan / insanity.py
Created June 25, 2012 17:23
Pure insanity in one line
(lambda args: map(lambda repo: __import__("os").system('git clone {0} {1}/{2}'.format(repo.git_url,args.backupdir,repo.name)),__import__("pygithub3").Github().repos.list(args.username).all()))((lambda : (lambda : [globals().update(argparser=__import__("argparse").ArgumentParser(description="Backup allyour github repos")),map(lambda arg: globals()["argparser"].add_argument(*arg["args"],**arg["kwargs"]),[{"args": ("username",),"kwargs": {"help": "A Github username"}},{"args": ("backupdir",),"kwargs": {"help": "The folder where you want your backups to do"}}]),globals()["argparser"].parse_args()])()[-1])())
@rossdylan
rossdylan / compose.py
Created August 7, 2012 16:37
Function composition in python
from functools import partial
def _composed(f, g, *args, **kwargs):
return f(g(*args, **kwargs))
def compose(*a):
try:
return partial(_composed, a[0], compose(*a[1:]))
except:
return a[0]
@rossdylan
rossdylan / spam.py
Created December 1, 2012 03:28
The Great Experiment
from twilio.rest import TwilioRestClient
from random import choice
import requests
import json
def random_issue():
issues = json.loads(requests.get("https://api.github.com/repos/ComputerScienceHouse/Drink-JS/issues").text)
return choice(issues)['body']
SPAM_SMS = [
@rossdylan
rossdylan / pipeline.py
Created January 16, 2013 01:40
Create pipelines of functions with optional arguments for those functions
"""
Misc tools/functions written by Ross Delinger
"""
def assemblePipeLine(*args, **kwargs):
"""
Given an arbitrary number of functions we create a pipeline where the output
is piped between functions. you can also specify a tuple of arguments that
should be passed to functions in the pipeline. The first arg is always the
@rossdylan
rossdylan / underscore.py
Created January 17, 2013 19:18
make the '_' variable match anything and everything.
"""
Author: Ross Delinger (rossdylan)
Really useless class that just makes _ equal whatever you throw at it
usage:
from underscore import _
if [_,_] == [1,"thing"]:
print "Anything goes!"
else:
print "Apprently this doesn't work"
"""
@rossdylan
rossdylan / curry.py
Created February 2, 2013 17:00
implicit function currying in python
"""
Decorator which takes a int which is the maximum number of args the decorated function can take
"""
class curryable(object):
def __init__(self, numArgs):
self.numArgs = numArgs
def __call__(self, func):
if self.numArgs > 0:
@curryable(self.numArgs-1)
def wrapper(*args, **kwargs):