Embedded in a string, a la Pymeta
parser = Parser("""
integer ::= \d+
atom ::= integer | s_expression
atoms ::= (atom,?\s*)*
s_expression ::= "(" atoms ")"
""")
class Looper(object): | |
def __init__(self, function): | |
function(self) | |
@Looper | |
def my_looper(self): | |
self.height = 130 | |
self.width = 120 |
products = { | |
"sam": "Subscription Asset Manager - Subscription Management", | |
"headpin": "Headpin - Open Source Subscription Management", | |
"katello", "Katello - Open Source Systems Management" | |
} | |
class Page(object): | |
"Base class for all Pages" | |
def __init__(self, testsetup): | |
"Initializer." |
Embedded in a string, a la Pymeta
parser = Parser("""
integer ::= \d+
atom ::= integer | s_expression
atoms ::= (atom,?\s*)*
s_expression ::= "(" atoms ")"
""")
class FalseClass(type): | |
def __int__(self): | |
return 13 | |
class C(object): | |
__metaclass__ = FalseClass | |
print int(C) |
from functools import wraps | |
def curried(fn, args=None): | |
args = args or () | |
@wraps(fn) | |
def curried_wrapper(*new_args): | |
if len(args + new_args) < fn.func_code.co_argcount: | |
return curried(fn, args + new_args) | |
else: |
require 'formula' | |
# Homebrew formula for das. | |
# das: http://github.com/jonpovey/das | |
# install with: | |
# `brew install https://gist.github.com/raw/2664491/das.rb` | |
# or save this file somewhere and "brew install das.rb" | |
class Das < Formula |
#include <sdl.h> | |
void event_loop(void (*on_keydown)(char), void (*on_loop)()) { | |
/* Given a function pointer to call on each new keypress, catch keypresses | |
* and pass them to it. | |
* | |
* TODO: a callback on quit. */ | |
SDL_Event event; | |
int cont = 1; |
inside object() as o: | |
a = 12 | |
b = 13 | |
o.a # -> 12 | |
o.b # -> 13 |
topics = { "Spell" : ["Love", "Revenge", "Etc"], | |
"Prayer" : ["Zeus", "Legba", "Circe"] } | |
choice = raw_input().rstrip() | |
print topics[choice] |
import Data.Monoid | |
-- Repeat an element every n times. | |
every :: Monoid a => Int -> a -> [a] | |
every n x = cycle $ replicate (n - 1) mempty ++ [x] | |
-- Pick either a number or a string. Always pick the number | |
-- over the empty string. | |
choose :: Show a => a -> String -> String | |
choose n s = if null s then show n else s |