Skip to content

Instantly share code, notes, and snippets.

View webwurst's full-sized avatar

Tobias Bradtke webwurst

View GitHub Profile
class Module
# Return all constants presently defined
def all_constants
# I <3 you ActiveSupport, really I do!
if defined?(ActiveSupport::Deprecation)
ActiveSupport::Deprecation.silence { __all_constants }
else
__all_constants
end
end
import simplejson as json
import lxml
class objectJSONEncoder(json.JSONEncoder):
"""A specialized JSON encoder that can handle simple lxml objectify types
>>> from lxml import objectify
>>> obj = objectify.fromstring("<Book><price>1.50</price><author>W. Shakespeare</author></Book>")
>>> objectJSONEncoder().encode(obj)
'{"price": 1.5, "author": "W. Shakespeare"}'
"""
curl -XPUT 'http://localhost:9200/dbparent/metadata/1' -d '{ "user" : "senthil", "Title" : "trying out Elastic Search"}'
curl -XPUT 'http://localhost:9200/dbparent/metadata/2' -d '{ "user" : "kumar", "Title" : "Elastic Search"}'
curl -XPUT 'http://localhost:9200/dbparent/child/_mapping' -d '{ "child" : { "_parent" : { "type" : "metadata" } }}'
curl -XPUT 'http://localhost:9200/dbparent/child/1?parent=1' -d '{ "tag" : "something"}'
curl -XGET 'http://localhost:9200/dbparent/_search' -d '{
@tmc
tmc / gist:776364
Created January 12, 2011 16:12
simple multiprocessing gevent echo server
import sys
from gevent import server
from multiprocessing import Process, current_process, cpu_count
def note(format, *args):
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
def echo(socket, address):
print 'New connection from %s:%s' % address
@tmc
tmc / gist:777085
Created January 12, 2011 23:08
multiprocessing gevent chat example
import sys
import gevent
from gevent.monkey import patch_all; patch_all()
from gevent import server, event, socket
from multiprocessing import Process, current_process, cpu_count
"""
Simple multiprocess StreamServer that proxies messages between clients.
Avoids using a multiprocessing.Event since it blocks on a semaphore.
@apeiros
apeiros / transliteration.rb
Created February 18, 2011 19:13
Unicode String operations, case mapping, natural sorting
# Encoding: utf-8
# The following code is under BSD 2-clause license
# -> http://en.wikipedia.org/wiki/BSD_licenses#2-clause_license_.28.22Simplified_BSD_License.22_or_.22FreeBSD_License.22.29
#
# Author: Stefan Rusterholz <stefan.rusterholz@gmail.com> - https://github.com/apeiros/
#
# A module to help with transliteration issues.
# Provides methods for:
# * Changing the case of characters/strings, mapping most latin characters
@davidaurelio
davidaurelio / create.js
Created February 22, 2011 14:48
Constructor-less inheritance for ECMAScript 5
var BaseObject = {
create: function create() {
var instance = Object.create(this);
instance._construct.apply(instance, arguments);
return instance;
},
extend: function extend(properties, propertyDescriptors) {
propertyDescriptors = propertyDescriptors || {};
# All of this testing was done on an AWS m1.large with a single Python
# process. I ran the commands multiple times and the numbers below are
# typical of the behavior, though they are the results of two particular
# cases
# Brubeck with Gevent
$ siege -c500 -t10s localhost:6767/brubeck
Lifting the server siege... done.
@mbostock
mbostock / .block
Last active February 8, 2016 23:52
d3.geo.tiler
license: gpl-3.0
@karmi
karmi / elastic_search_ngram_analyzer_for_urls.sh
Created May 24, 2011 15:32
NGram Analyzer in ElasticSearch
# ========================================
# Testing n-gram analysis in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/ngram_test
curl -X PUT localhost:9200/ngram_test -d '
{
"settings" : {
"index" : {
"analysis" : {