Skip to content

Instantly share code, notes, and snippets.

View uniphil's full-sized avatar

phil uniphil

View GitHub Profile
@uniphil
uniphil / init.sh
Last active December 20, 2015 21:25
linux development python focus
# this is not actually a shell script, just some self-reminders for stuff to do on new systems. mind the git configs.
# lets be serious
sudo apt-get install aptitude
# git.
sudo aptitude install git meld
git config --global user.name "Your Name Here"
git config --global user.email "[email protected]"
@uniphil
uniphil / stupid_e.py
Created March 11, 2013 03:14
just... don't do this.
In [1]: class RaiseEWithCaret(object):
...: def __xor__(self, exponent):
...: from math import exp
...: return exp(exponent)
...:
In [2]: e = RaiseEWithCaret()
In [3]: e^1
Out[3]: 2.718281828459045
@uniphil
uniphil / except.py
Last active December 14, 2015 22:19
__getattr__ is called if __getattribute__ raises an AttributeError. Raising AttributeError in __getattr__ is a bad idea...
>>> class AttrDict(dict):
... """A class that is annoyingly difficult to get right in python."""
... def __getattr__(self, attr):
... """access items by key with dot notation"""
... try:
... return super(AttrDict, self).__getitem__(attr)
... except KeyError as e:
... raise AttributeError(e) # translate the error where applicable yay
...
>>>
@uniphil
uniphil / postactivate
Last active December 27, 2015 02:19
Dead-simple environment variable management for virtualenvs (using virtualenvwrapper).
#!/bin/bash
# This hook is run after every virtualenv is activated.
export CONFIG=$VIRTUAL_ENV/bin/postactivate
@uniphil
uniphil / gist:7777590
Created December 3, 2013 21:13
send_from_directory

Say you have a package with this layout:

my_project/
    my_app/
        files/
            im_a_file.txt
        __init__.py
    run_my_app.py
@uniphil
uniphil / 1_super_wat.py
Last active August 29, 2015 13:57
Python: decorated class super wat
"""
The class decorator screws up the inheritance, so super() gets confused and doesn't super superly.
"""
def make_awesome(cls):
class Awesomefied(cls):
"""make this class awesomer"""
return Awesomefied
@uniphil
uniphil / simple-win.js
Last active August 29, 2015 13:57
5x5 sometimes lucky 2048 masher
// Sometimes solves kortaggio's 5x5 variant of 2048: http://kortaggio.github.io/2048/
// Open the javascript console with ctrl+j (in chromium), and copy past this in.
// export the game manager into the global namespace
GameManager.prototype.__original_actuate = GameManager.prototype.actuate;
GameManager.prototype.actuate = function() {
window.gm = this;
this.__original_actuate();
GameManager.prototype.actuate = GameManager.prototype.__original_actuate;
};
@uniphil
uniphil / auto_treebuilder_test.py
Last active December 11, 2023 23:22
pygit2 auto treebuilder
"""
Defines a function `auto_insert` to help with
`pygit2.Repository.TreeBuilder`s.
Just create the top-level `TreeBuilder`, and it will handle all subtree
creation if you give it paths.
"""
import shutil
from tempfile import mkdtemp
55
35
30
46
38
60
77
77
57
30
@uniphil
uniphil / pizza.ipynb
Last active August 29, 2015 14:06
pizza prices
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.