Skip to content

Instantly share code, notes, and snippets.

@renyi
renyi / admin.py
Created September 2, 2012 09:37
Mezzanine Translatable
from django.contrib import admin
from mezzanine.conf import settings
from mezzanine.core.admin import TabularDynamicInlineAdmin
if "mezzanine.pages" in settings.INSTALLED_APPS:
from mezzanine.pages.models import RichTextPage, Link
from mezzanine.pages.admin import PageAdmin, LinkAdmin
from models import TransRichTextPage, TransLinkPage
#
@butaji
butaji / server.hs
Created May 29, 2011 20:27
Simple Haskell web server
import Control.Monad
import Data.Char
import System.IO
import Network
import Data.Time.LocalTime
data RequestType = GET | POST deriving (Show)
data Request = Request { rtype :: RequestType, path :: String, options :: [(String,String)] }
data Response = Response { version :: String, statuscode :: Int }
@jorgeortiz85
jorgeortiz85 / PrivateMethodCaller.scala
Created April 7, 2011 15:41
Calling private methods in Scala
// Usage:
// p(instance)('privateMethod)(arg1, arg2, arg3)
class PrivateMethodCaller(x: AnyRef, methodName: String) {
def apply(_args: Any*): Any = {
val args = _args.map(_.asInstanceOf[AnyRef])
def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass)
val parents = _parents.takeWhile(_ != null).toList
val methods = parents.flatMap(_.getDeclaredMethods)
val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found"))