Skip to content

Instantly share code, notes, and snippets.

@mallipeddi
mallipeddi / gist:178330
Created August 31, 2009 07:20
Python meta-classes
"""
Discovered http://gulopine.gamemusic.org/2008/jan/10/simple-plugin-framework/ which describes a simple technique for supporting plugins in your Python app.
Few lessons learned:
* __new__() returns an instance of a class which is then sent to __init__() as the first arg.
* Class variables are shared across all classes (original class and its subclasses). This is why "plugins" can be shared between B and C below. For more info on this topic read Martin Fowler's article on ClassInstanceVariables - http://martinfowler.com/bliki/ClassInstanceVariable.html (Ruby and Python seem to exhibit the same behavior in this case).
"""
@mallipeddi
mallipeddi / tumblore.clj
Created December 1, 2009 11:53
Simple Tumblr.com blog backup utility
;; Tumblore - Tumblr blog backup tool
;;
;; Harish Mallipeddi
;; Dec 1 2009
(ns in.poundbang.tumblore
(:use [clojure.http.client :only [request]]
[clojure.contrib.duck-streams :only [spit]])
(:import (java.io ByteArrayInputStream)))
@mallipeddi
mallipeddi / gist:248184
Created December 3, 2009 14:13
select() on pipes to offload work to thread-pool
"""
Simple python program demonstrating how certain blocking syscalls can be offloaded to a thread-pool and
then be able to fetch the results from these system calls in a non-blocking way by doing select() on
a pipe between the main thread and the threads in the pool.
This is the technique being used by node.js to offer a unified non-blocking Javascript API even for
things like file I/O which is traditionally done via blocking syscalls. This idea was described by
Ryan Dahl at JSConfEU 2009.
-- Harish Mallipeddi - Dec 3 2009
Setting up Eclipse for Hadoop Dev
* Create a new Java project from existing source (point to the top-level folder which has src/ folder inside).
* Turn off build-automatically from “Projects” menu.
* Right-click build.xml, choose "Run as > Ant build..."; Choose “compile, eclipse-files” targets.
* Build once.
"""
Emulating Ruby-style code blocks in Python.
This example was demonstrated in the PyCon'10 talk titled "Python Metaprogramming".
"""
import sys
import types
def receive_block(func):
public class Parser {
public static <T> Map<String, T> getMapFromKeyValuePairs(String str, Convertor<T> convertor) {
Map<String, T> map = new HashMap<String, T>();
String[] symbols = str.split(",");
if (symbols.length > 0) {
for (String symbol : symbols) {
String[] tuple = symbol.split(":");
if (tuple.length == 2) {
try {
#!/bin/sh
LOCAL=$1
REMOTE=$2
BASE=$3
araxiscompare -nowait -2 "$LOCAL" "$REMOTE"
INSTRUCTIONS FOR GETTING MEMPROF WORKING ON SNOW LEOPARD
We'll compile and install a different version of ruby and ruby-gems alongside the default versions that ship with Snow Leopard.
Compile and install ruby
Get ruby-1.8.7-p299.tar.gz (or the latest version) & untar it somewhere
./configure --prefix=/path/to/ruby/directory/you/want \
--with-readline-dir=/opt/local \
class Foo
def foo
puts "fofo"
end
end
# Module#instance_method
# => returns an UnboundMethod object
unbound_foo = Foo.instance_method(:foo)
p unbound_foo # => #<UnboundMethod: Foo#foo>
lib/action_controller/dispatcher.rb
dispatch method
calls handle_request
calls Routing::Routes#recognize(request) to figure out the correct 'controller'
once the controller has been identified, calls controller.process
if an exception gets thrown, do failsafe_rescue(exception)
failsafe_rescue
calls ApplicationController or ActionController::Base's process_with_exception (for Base, it's defined in rescue.rb)
lib/action_controller/rescue.rb