Skip to content

Instantly share code, notes, and snippets.

user_admin = AdminBundle(User, 'user', 'admin/user')
user_admin.push_bundle(application)
import bundle
class Room(bundle.APIBundle):
@bundle.expose('/<int:id>')
def get(self, id):
"Return room info"
return {}
@bundle.expose('/<int:id>/message', methods=['POST'])
def post_message(self, id):
apis = list(bundle.dump_api(app))
for m in apis:
print m
{'name': 'room.post_message', 'url': '/room/{id}/message', 'args': ['id'], 'methods': ['POST'], 'host': '', 'desc': 'Post new message'}
{'name': 'room.get', 'url': '/room/{id}', 'args': ['id'], 'methods': ['GET'], 'host': '', 'desc': 'Return room info'}
api = bundle.generate_api(apis, '127.0.0.1:5000')
print api.room.get.__dict__
print 'API call result', api.room.get(id=1)
{'host': '127.0.0.1:5000', 'method': {'name': 'get', 'url': '/room/{id}', 'args': ['id'], 'methods': ['GET'], 'host': '', 'desc': 'Return room info'}}
{}
@Deepwalker
Deepwalker / validate.erl
Created November 5, 2011 00:26
Small erlang data validator
-module(validate).
-compile(export_all).
list_to_number(L) ->
try list_to_float(L)
catch
error:badarg -> list_to_integer(L)
end.
@Deepwalker
Deepwalker / plasma-restart
Created November 19, 2011 22:01
plasma-restart
#! /bin/sh
kbuildsycoca4
kquitapp plasma-desktop
plasma-desktop
-module(fact).
-export([fac/1, fac2/1, benchmark/1]).
fac(1) ->
1;
fac(N) ->
N * fac(N - 1).
fac2(N) ->
import time
from jinja2 import Template as j
from django.template import Template as d
from django.template import Context
template = """
Good template without includes, only cycles.
{% for i in d %}
<p>{{ i }}</p>
import time
from jinja2 import Template as j
from django.template import Template as d
from django.template import Context
template = """
<div>
{% for priority in priorities %}
<div class="{{ priority.slug }}" priority="{{ priority.id }}" max_prods="{{ priority.max_prods }}" rank="{{ priority.rank }}">
@Deepwalker
Deepwalker / rect.erl
Created December 10, 2011 13:26
rects intersection
%
% Rect library - work with rects
%
-module(rect).
-export([intersect/2, normalize/1]).
intersect(R1, R2) ->
{{X1, Y1}, {X2, Y2}} = R1,