Skip to content

Instantly share code, notes, and snippets.

@dheaney
dheaney / first_default_arg.py
Last active August 29, 2015 13:56
Get the name of the first default argument from a python function
import inspect
def first_default_arg(func):
try:
argspec = inspect.getargspec(func)
return zip(argspec.args[-len(argspec.defaults):], argspec.defaults)[0][0]
except:
return None
# def action(one, two, three=3): pass
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
int i;
for(i = 0; i < 50; i++) {
cout << rand() % 2 << endl;
}
class RSPD(object):
def __init__(self, base10):
#if base10 > 210:
# raise NotImplemented
self.values = []
self.value = str()
remainder = int()
self.primes = primes_less_than(base10)
@dheaney
dheaney / Rakefile
Last active January 2, 2016 23:09
Set your Gravatar account image to your Address Book entry on your Mac.
# Copyright (c) 2012 David Heaney
require 'erb'
UNAME = ENV['USER']
AGENT = "/Users/#{UNAME}/Library/LaunchAgents/com.dejay.gravatar-mac.plist"
desc "Install Gravatar-Mac!"
task :install do
puts "Please enter the email that you wish to use for Gravatar-Mac:"
@dheaney
dheaney / Autonomous
Created January 10, 2014 03:21
Autonomous
Pseudocode for Autonomous Period
Start with block in arm. Position robot.
0. Start timer.
1. Travel forward until IR beacon is in section 5.
2. Stop timer. Save value as n.
2. Rotate 90 degrees.
3. Travel forward until distance is less than ___.
4. Raise arm.
import subprocess
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.stdin.write(your_data_here)
#!/usr/bin/env python
import os, time
import wikipedia
from datetime import datetime
import smtplib
user = '[email protected]'
pwd = 'SECRET'
path = '/Users/dejay/Dropbox/IFTTT/SMS/shell.iftt.txt'
@dheaney
dheaney / test.py
Last active December 30, 2015 21:19
import urwid
def show_or_exit(key):
if key in ('q', 'Q'):
raise urwid.ExitMainLoop()
txt.set_text(repr(key))
banner = u"""
____ __ __ __
/ __ \__ __/ /_/ /_ ________ ____ _/ /__
@dheaney
dheaney / intsigfig.py
Created November 27, 2013 18:04
Return integer number of significant figures from an integer
from math import floor, log10
def sigfigs(x):
while((x % 10) == 0):
x = x / 10
return int(floor(log10(abs(x))) + 1)
from outbreak import Game
import inspect
game = Game(3 , 0)
player = game.players[0]
inspect.getargspec(player.drive)[0] # => ['self', 'city']
inspect.getargspec(inspect.getmembers(player, predicate=inspect.ismethod)[3][1])[0] # => ['self', 'city']
methods = [ x for x in inspect.getmembers(player,