Skip to content

Instantly share code, notes, and snippets.

import System
// http://blog.8thlight.com/uncle-bob/2012/04/20/Why-Is-Estimating-So-Hard.html
// estimated to take 5, done in 4 ;)
text = """
Four score and seven years ago our fathers brought forth upon this continent a new nation, conceived in liberty and dedicated to the proposition that all men are created equal…
"""
words = /\s+/.Split(text.Trim())
currentLineLength = 0
elements, separator = argv
entries = elements.Split((separator,), System.StringSplitOptions.RemoveEmptyEntries)
for e in entries: print e
import System.Text.RegularExpressions
while true:
heads = /changeset:\s+(?<revision>\d+)(.|\n)+?summary:\s+.+\n/.Matches(shell("hg", "heads"))
break if len(heads) < 2
for head as Match in heads:
continue if /tag:\s+tip/.IsMatch(head.Value)
@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))
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 / 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()
@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") {}
}
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: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);
}
}
using UnityScript.Scripting;
namespace Evaluator
{
public class Test
{
private static EvaluationContext context = new EvaluationContext();
public static void Run()
{