Skip to content

Instantly share code, notes, and snippets.

View heynemann's full-sized avatar

Bernardo Heynemann heynemann

View GitHub Profile
@heynemann
heynemann / gist:112032
Created May 15, 2009 02:57
Sample code for before Pynq
collection = some_method_return()
filtered = []
for item in collection:
if item.property + item.another > 10:
filtered.append(item)
return filtered.sort()
@heynemann
heynemann / gist:112035
Created May 15, 2009 03:02
Pynq query
From(collection)
.where("item.property + item.value > 10")
.order_by("item.some_order_property")
.select_many()
# this returns an ordered collectin with only the items that
# have the sum of property and value greater than 10
From(collection)
.where("item.some_boolean or (item.other_boolean and item.another_boolean)")
.order_by("item.some_order_property")
.select("name","age","sex","salary")
# This query returns a new collection transformed from the original.
# The items in this new collection are from a class called
# Dynamic_Item and feature only the four selected properties,
# instead of all the properties of the original items in 'collection'.
# The where clause is observed as well, since only the items that
From(collection)
.select("name","age","sex","salary","salary + bonus")
# This query returns the evaluated return of salary + bonus
# as dynamic_4. This is really useful to perform calculations
# on the fly.
From(collection)
.order_by("-(salary + bonus)")
.select("name","age","sex","salary","salary + bonus")
# This query returns the evaluated return of salary + bonus
# as dynamic_4 and sorts through this expression in desc order.
#!/usr/bin/ruby
#
# I deliberately didn't DRY /usr/local references into a variable as this
# script will not "just work" if you change the destination directory. However
# please feel free to fork it and make that possible.
#
# If you do fork, please ensure you add a comment here that explains what the
# changes are intended to do and how well you tested them.
#
# 30th March 2010:
export TERM="xterm-color"
export EDITOR='mate -w'
export CLICOLOR=1
alias ls="ls -G"
PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] "
alias egrep="egrep --colour"
alias grep="egrep --colour"
export PYTHONPATH=$PYTHONPATH:$HOME/usr/python-libs
export PATH=$PATH:$HOME/usr/bin
export GEM_HOME='/usr/local/Cellar/gems/1.8'
@heynemann
heynemann / gist:951663
Created May 2, 2011 14:16
Pyvows better error reporting
✗ Should equal regular http get
Expected body of /home/heynemann/dev/thumbor/vows/fixtures/conselheira_tutelar.jpg to match topic, but it didn't
Traceback (most recent call last):
File "/home/heynemann/.virtualenvs/home/lib/python2.6/site-packages/pyvows/runner.py", line 113, in async_run_vow
result = member(context_instance, topic)
File "/home/heynemann/dev/thumbor/vows/http_loader_vows.py", line 76, in should_equal_regular_http_get
expect(topic).to_match_contents_of(fixture_for('conselheira_tutelar.jpg'))
File "/home/heynemann/.virtualenvs/home/lib/python2.6/site-packages/pyvows/core.py", line 50, in assert_topic
return getattr(Vows.Assert, method_name)(self.topic, *args, **kw)
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8888
Document Path: /healthcheck
Document Length: 7 bytes
Concurrency Level: 50
Time taken for tests: 19.028 seconds
Complete requests: 100000
@heynemann
heynemann / libevent.cpp
Created June 21, 2011 03:35
libevent hello world server
#include <event.h>
#include <evhttp.h>
#include <cstdio>
#include <iostream>
#define SRVR_SIGNATURE "dirq v 0.0.1"
void router(struct evhttp_request *r, void *arg) {
// just testing retrieval of URI
const char *uri = evhttp_request_uri(r);