Skip to content

Instantly share code, notes, and snippets.

import Mono.Cecil
import Mono.Cecil.Cil
import System
import System.Collections
import Boo.Lang.PatternMatching
def CreateApiStub(fromAssembly as string, toAssembly as string):
module = ModuleDefinition.ReadModule(fromAssembly)
notImplementedExceptionCtor = module.Import(typeof(System.NotImplementedException).GetConstructor(array[of System.Type](0)))
import System.Linq.Enumerable
words = ("blueberry", "chimpanzee", "abacus", "banana", "apple", "cheese")
wordGroups = words.GroupBy({ w | w[0] })
for g in wordGroups:
print "Words that start with the letter $(g.Key):"
for word in g: print "\t$word"
@bamboo
bamboo / traceable_property.boo
Created October 28, 2010 17:08
macros are a beautiful thing
macro traceable_property:
case [| traceable_property $name as $type |]:
backingField = [|
private $("_$name") as $type
|]
yield backingField
yield [|
public $name:
@bamboo
bamboo / DeepProfilingAttribute.boo
Created January 19, 2011 20:12
Wraps every method with Profiler.BeginSample/Profiler.EndSample calls.
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
class DeepProfilingAttribute(AbstractAstAttribute):
"""
Wraps every method with Profiler.BeginSample/Profiler.EndSample calls.
Save it to the Plugins folder of your Unity project and enable it on a per script basis using:
@script DeepProfiling()
@bamboo
bamboo / assign.boo
Created February 9, 2011 19:47
Meta method expanding named arguments into property assignments.
import System
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.Services
import Boo.Lang.Environments
import Boo.Lang.Compiler.MetaProgramming
[meta]
def assign(e as MethodInvocationExpression):
"""
package UnityEngine.Serialization {
class ActionScriptDeserializer {
public static function Deserialize(instance: IDeserializable, buffer: ByteArray, offset: int): int {
var reader = new SerializedStateReader(buffer, offset);
instance.Deserialize(reader);
return reader.offset;
}
}
@bamboo
bamboo / gist:980973
Created May 19, 2011 15:08
alchemy - struct instantiation
static AS3_Val Vector3f_DefaultValue() {
static AS3_Val (*DefaultValueShim)() = NULL;
if (DefaultValueShim == NULL) {
AS3_Val UnityEngine = AS3_String("UnityEngine");
AS3_Val Vector3_class = AS3_NSGetS(UnityEngine, "Vector3");
AS3_Val DefaultValue = AS3_GetS(Vector3_class, "DefaultValue");
DefaultValueShim = AS3_Shim(DefaultValue, null, "AS3ValType", false);
AS3_Release(DefaultValue);
AS3_Release(Vector3_class);
AS3_Release(UnityEngine);
@bamboo
bamboo / MacroResolvingTypeArgument.boo
Created May 27, 2011 14:03
Macro resolving a type argument
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.MetaProgramming // compile_
import Boo.Lang.Compiler.TypeSystem
import Boo.Lang.Compiler.TypeSystem.Services
import Boo.Lang.Environments
struct Vector3:
x as single
y as single
@bamboo
bamboo / fogbugz.clj
Created June 14, 2011 18:17
interacting with fogbugz using clojure
(ns fogbugz
(:use [clojure.xml :as xml]))
(def *base-url* "https://intra.unity3d.com/fogbugz/api.asp?")
(defn query-string-from-map [m]
(apply str (interpose "&" (for [[key value] m] (str (name key) "=" value)))))
(defn rest-call [args]
(let [query-string (query-string-from-map args)]
@bamboo
bamboo / gist:1063808
Created July 4, 2011 19:16
Emacs: opening all actionscript files in a directory
(require 'find-lisp)
(defun open-actionscript-files-in (dir-path)
(interactive "s")
(mapc 'find-file (find-lisp-find-files dir-path "\\.as$")))