Skip to content

Instantly share code, notes, and snippets.

@bamboo
bamboo / gist:1109212
Created July 27, 2011 12:06
Zip and Tuple.Create
foreach (var argAndParameterType in invocationExpression.Arguments.Zip(method.ParameterTypes(), Tuple.Create))
PreserveSemanticsForInvocationArgument(argAndParameterType.Item1, argAndParameterType.Item2);
@bamboo
bamboo / strip-non-tip-heads.boo
Created August 8, 2011 18:18
stripping all revisions from a non tip head in mercurial
def hg(command):
return shell("hg", command)
def strip(rev):
return hg("strip $rev")
def heads():
return hg("heads")
def nextNonTipRevision():
@bamboo
bamboo / evalstresstest.c
Created September 9, 2011 20:13
Eval with appdomain reload
#include "stdafx.h"
#include <glib.h>
#include <mono/mini/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/threads.h>
extern "C" {
#include <mono/metadata/mono-debug.h>
}
#include <mono/metadata/mono-gc.h>
using UnityScript.Scripting;
namespace Evaluator
{
public class Test
{
private static EvaluationContext context = new EvaluationContext();
public static void Run()
{
@bamboo
bamboo / gist:1277975
Created October 11, 2011 12:43
xpath in unityscript
import System.Xml;
function printAllTypes(file : String) {
var doc = new XmlDocument();
doc.PreserveWhitespace = false;
doc.Load(file);
for (var text: XmlText in doc.SelectNodes("//element/type/text()")) {
print(text.Value);
}
}
import UnityEngine
import UnityEditor
[MenuItem("Tools/Remove Unsupported Components")]
def RemoveUnsupportedComponents():
unsupported = AudioChorusFilter, AudioDistortionFilter, AudioEchoFilter, AudioHighPassFilter, AudioLowPassFilter, AudioReverbFilter
for u in unsupported:
for o in GameObject.FindSceneObjectsOfType(u):
Debug.Log("destroying $o")
GameObject.DestroyImmediate(o)
@bamboo
bamboo / gist:1302345
Created October 20, 2011 20:50
annoying constructor chaining mapping
public abstract class Base
{
public Base(string s) {}
}
public class ChainToBase : Base
{
public ChainToBase() : base("foo") {}
}
@bamboo
bamboo / gist:1314499
Created October 25, 2011 22:04
macro resolving a type after macro expansion
import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.TypeSystem
import Boo.Lang.Compiler.TypeSystem.Services
import Boo.Lang.Compiler.MetaProgramming
import Boo.Lang.Environments
macro delegate:
case [| delegate $field as $fieldType |]:
enclosingType = delegate.GetAncestor of TypeDefinition()
IL_0000: ldarg.0
IL_0001: ldfld class CompilerGenerated.__test_flakeDelegate$callable0$4_21__ test::flakeDelegate
IL_0006: ldnull
IL_0007: call bool class [mscorlib]System.MulticastDelegate::op_Inequality(class [mscorlib]System.MulticastDelegate, class [mscorlib]System.MulticastDelegate)
IL_000c: brfalse IL_0021
IL_0011: ldarg.0
IL_0012: ldfld class CompilerGenerated.__test_flakeDelegate$callable0$4_21__ test::flakeDelegate
IL_0017: callvirt instance void class CompilerGenerated.__test_flakeDelegate$callable0$4_21__::Invoke()
IL_001c: br IL_002b
@bamboo
bamboo / copy-hg-changes-to.boo
Created March 1, 2012 18:06
copy all local hg changes to another folder
import System.IO
import Boo.Lang.PatternMatching
targetFolder = argv[0]
changes = ((statusLine[:1], statusLine[2:]) for statusLine in /\n/.Split(shell("hg", "st")) if len(statusLine) > 0)
for status, file in changes:
targetFile = Path.Combine(targetFolder, file)
match status:
case "M" | "?":
Directory.CreateDirectory(Path.GetDirectoryName(targetFile))