Skip to content

Instantly share code, notes, and snippets.

View AlexeyMK's full-sized avatar

Alexey Komissarouk AlexeyMK

View GitHub Profile
@AlexeyMK
AlexeyMK / gist:1240101
Created September 25, 2011 01:41
Strategy Decorator for Ants AI challenge
### possible_moves = ['e':0, 'n':0, 'w':0, 's':0, 'halt':0]
### extra = {} # pass info to others if needed
class Strategies:
INITIAL_MOVES = dict([(m, 0) for m in AIM.keys()])
@classmethod
def best_option(cls, moves):
return max(list(moves.keys()), key=lambda d: moves[d])
@AlexeyMK
AlexeyMK / gist:1266808
Created October 6, 2011 08:05
sponsor filterer
# IE, resume_filter.py resumes.tsv 10gen mongodb mongo
# creates 10gen.tsv, which has all participants who mentioned they were
# excited about 10gen (however they called it) and removes the last column
# (which lists companies that participants are interested in)
import fileinput
from sys import argv
sponsor_names = argv[2:]
output = file(argv[2] + ".tsv", 'w')
reading_from = fileinput.input(argv[1])
@AlexeyMK
AlexeyMK / seasprint.sh
Created January 19, 2012 18:18
Seasprint (free printing from the command line on eniac)
# Put in .bashrc
# By Matt Croop, but originally by Jon McCaffrey or Ryan Gormley or something.
# Usage: seasprint foo.pdf
function seasprint() {
cat "$1" | ssh you@eniac.seas.upenn.edu lpr -P169
}
#Usage: listprinters
function listprinters() {
@AlexeyMK
AlexeyMK / valentine.py
Created February 14, 2012 05:35
JSON API Design Prototype
# Just a prototype of a JSON API framework that I thought up because it'd be nice to have
# for API work I've done before - feedback very much welcome.
#
# all models have a 'short' and a full version
@canonical_url('/users/:id')
class User(Model): # this model is both an ORM-style model and a REST resource.
id = ModelField.Integer(unique=True)
name = ModelField.String(length=25)
email = ModelField.String(length=55, in_short=None)
@AlexeyMK
AlexeyMK / gist:1954251
Created March 2, 2012 00:27
PEP8 pre-commit hook in Python
#!/usr/bin/env python
from __future__ import with_statement
import os
import shutil
import subprocess
import sys
import tempfile
def system(*args, **kwargs):
@AlexeyMK
AlexeyMK / gist:5321752
Last active December 15, 2015 20:49
permute some letters
import string
from random import shuffle
alphabet = list(string.lowercase + string.digits)
shuffle(alphabet)
print "".join(alphabet)
@AlexeyMK
AlexeyMK / d.py
Last active January 3, 2022 22:01
A version of Coffeescript's {name, age, location} translating to {name: name, age: age, location: location} for Python, using ast.py
def d(*args):
d_name = 'd'
import inspect
cur = inspect.currentframe()
calling_frame = inspect.getouterframes(cur)[1]
frameinfo = inspect.getframeinfo(calling_frame[0])
string = frameinfo.code_context[0].strip()
import ast
ast_module = ast.parse(string)
@AlexeyMK
AlexeyMK / simply
Last active August 29, 2015 13:56
simply.title('Hello PennApps!');
@AlexeyMK
AlexeyMK / counter.js
Last active August 29, 2015 13:56
simply.js counter
var count = parseInt(localStorage.getItem('count')) || 0;
simply.on('singleClick', function(e) {
if (e.button === 'up') {
count+=1; simply.subtitle(count);
} else if (e.button === 'down') {
count-=1; simply.subtitle(count); }
localStorage.setItem('count', count);
});
@AlexeyMK
AlexeyMK / talk
Created April 25, 2014 02:53
Houston April 2014 Update
Talk Links
Houston: http://github.com/gterrono/houston
Atmosphere: atmosphere.meteor.com/package/houston
Merging with Ogno-Admin!
Demo: http://houstondemo.meteor.com
Adding Custom Menu Code: http://imgur.com/qfJC3WF