Skip to content

Instantly share code, notes, and snippets.

View solex's full-sized avatar

Oleksii Solianik solex

View GitHub Profile
@solex
solex / antigravity.py
Created October 28, 2010 09:41
Populates all classes with "altitude", measured as the number of lines from the bottom of the file. And the very useful "fly" function
import inspect
class GravitationalError(Exception):
pass
class Fly(object):
def __get__(self, instance=None, owner=None):
def fly(*args, **kwargs):
alt_str = "Flying at the height of %d lines. " % owner.altitude
@solex
solex / antigravity_test.py
Created October 28, 2010 09:45
Antigravity usage example
class Dummy(object):
answer = 42
class Foo:
pass
class Bar:
@solex
solex / pythonify.js
Created November 11, 2010 11:46
The bookmarklet that makes Reddit comments look like Python
javascript:(function(){$('.commentarea%20.tagline').each(function(){var%20u=$(this).find('a.author'),t=$(this).find('.unvoted').html();var%20p=t?t.split('%20')[0]:"None";$(this).empty().append('<span%20style="color:#00f;font-weight:bold">def%20</span>').append(u).append('(points='+p+'):')});$('.commentarea%20.usertext-body').css('padding-left',24).find('.md').css('color','#393').prepend('"""').append('"""');$('.commentarea%20.flat-list.buttons').each(function(){$(this).appendTo($($(this).parents('.comment')[0]).css('padding-bottom','16px'));$(this).find('li').prepend('<span%20style="color:#00f;font-weight:bold;padding-left:42px">return</span>%20').not('.first').remove()})})();
import json
from json.decoder import JSONArray
from json.scanner import py_make_scanner
class UnorderedList(list):
"""
Works like a normal list, except the order of elements doesn't matter on
comparison