Skip to content

Instantly share code, notes, and snippets.

@drslump
drslump / fire.py
Created April 18, 2012 20:54
Fire model effect for ansi terminals
#!/usr/bin/env python
# coding: utf-8
"""
Fire model effect for ansi terminals.
Model based on http://freespace.virgin.net/hugo.elias/models/m_fire.htm
"""
__author__ = "Iván -DrSlump- Montes"
@drslump
drslump / mediakeys.py
Created June 4, 2012 19:13
Act upon media keys in a Mac under OSX
#!/usr/bin/python
import subprocess
# PyObjC-related imports
from AppKit import NSApplication, NSSystemDefined
from PyObjCTools import AppHelper
KEY_UP = 11
@drslump
drslump / mkd.sh
Created July 5, 2012 09:31
Preview markdown files in the terminal using ruby's ronn
#!/bin/sh
if [ "$1" = "" ]
then
echo "Usage: $0 path/to/filename.markdown"
exit
fi
tmpfile=`mktemp -t ronn`
/usr/local/lib/ruby/gems/1.9.1/gems/ronn-0.7.3/bin/ronn -r --pipe $1 > $tmpfile
man $tmpfile
@drslump
drslump / negatives.phpt
Created September 19, 2012 11:30
protobuf int negatives test
--TEST--
Tests the encoding of int32 and int64 types including negative values
--FILE--
<?php
extension_loaded('protobuf') or dl('protobuf.' . PHP_SHLIB_SUFFIX);
// Create a message descriptor resource
$m = protobuf_desc_message();
// msg(res), num(int), label(int), type(int), [name, [flag(int), [nested(res)]]] : bool
protobuf_desc_field($m, 1, 1 /*optional*/, 5 /*INT32*/, 'int32');
@drslump
drslump / asyncawait.boo
Created November 10, 2012 22:14
async/await demo
# Using Python/Mozilla style coroutine-like generators (yield as
# expression) and Boo's metaprogramming facilities to easily model
# asynchronous APIs (Promise/A based) into sequential code logic.
# Avoiding the need to for nested callbacks and handling error
# conditions with standard try/except blocks.
#
# Change the ENDPOINT variable to an invalid URL to check the
# error handling.
#
@drslump
drslump / async-await.boo
Created November 29, 2012 07:40
PDI DEVCON1 - BooJs code examples
import Async
[async] def foo():
print 'start'
try:
for i in range(3):
print i
for delay in (1000ms, 5s):
print "Waiting $delay..."
namespace consoleApplication1
import System
import System.IO
class ParserClass:
public CurrentCommand as string:
get:
return self._currentCommand

Boo Succinctly Revealed (second edition)

By Rolly Noel, Copyright 2013

THIS DOCUMENT DOESN'T COVER ANYTHING THAT NEEDS AN IMPORT (except for System) FIRST DEFINITION OF BOO LANGUAGE ITEMS IS IN BOLD IN THIS DOCUMENT, LINES OF DESCRIPTION (NOT CODE) START WITH "#", AND ARE CONTINUED WITH " "

print'ACompleteBooprogram' # O/Ps(outputs)'ACompleteBooprogram'
#!/usr/bin/env python
#-*- coding: utf-8 -*-
u"""
Created on May 15, 2013
@author: pablito56
@license: MIT
@contact: pablito56@gmail.com
# The API designer (library author) exposes these types
interface ISeek:
def seek(offset as int)
def foo(stream as ISeek):
stream.seek(0)
# The API consumer (library user) wants to use the API but
# doesn't want to (or cannot) use the type hierarchy defined