Skip to content

Instantly share code, notes, and snippets.

View 5alamander's full-sized avatar

ForgiveMyAwfulEngilsh 5alamander

View GitHub Profile
@5alamander
5alamander / binding0.rb
Created May 12, 2016 15:24
Ruby binding of a Proc
# take a note of http://stackoverflow.com/questions/10058996/changing-the-binding-of-a-proc-in-ruby
class Proc
def call_with_vars(vars, *args)
Struct.new(*vars.keys).new(*vars.values).instance_exec(*args, &self)
end
end
# test
lambda { foo }.call_with_vars(:foo => 3) # => 3
lambda { |a| foo + a }.call_with_vars({:foo => 3}, 1) # => 4
@5alamander
5alamander / orderedhash.rb
Created May 13, 2016 13:29
ruby Ordered-hash, add method to a eigen-class
hash={}
hash.instance_eval do # if you want this for all hashes, replace this line with class Hash
def []=(key,val)
ordered_keys << key
super(key,val)
end
def ordered_keys
@ordered_keys ||= []
@5alamander
5alamander / CardIdentifier.cs
Last active June 1, 2016 03:17
TargetTrack for HiAR-SDK
using UnityEngine;
using System.Collections.Generic;
public interface ICardIdentifierListener {
void OnTargetChange(Transform t);
void OnTargetFound(Transform t);
void OnTargetTracked(Transform t);
void OnTargetLost(Transform t);
}
@5alamander
5alamander / DecoratorEditor.cs
Last active April 17, 2024 00:25 — forked from liortal53/DecoratorEditor.cs
Unity, Custom Menu, decorate the build in editor
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
/// <summary>
/// A base class for creating editors that decorate Unity's built-in editor types.
/// </summary>
public abstract class DecoratorEditor : Editor
@5alamander
5alamander / MyHierarchyMenu.cs
Created September 5, 2016 06:25
Unity, Custom Menu, in Hierarchy
using UnityEngine;
using UnityEditor;
using System.Collections;
public class MyHierarchyMenu
{
[MenuItem("Window/Test/a")]
static void Test()
{
}
@5alamander
5alamander / NetworkManagerHud.cs
Created September 10, 2016 12:00
Unity, Customize NetworkManagerHud
#if ENABLE_UNET
namespace UnityEngine.Networking
{
[AddComponentMenu("Network/NetworkManagerHUD")]
[RequireComponent(typeof(NetworkManager))]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public class NetworkManagerHUD : MonoBehaviour
{
public NetworkManager manager;
csp = require 'js-csp'
player = (name, table) ->
loop
ball = yield csp.take table
if ball is csp.CLOSED
console.log name + ": table's gone"
return
ball.hits += 1
console.log name + " " + ball.hits
@5alamander
5alamander / csp_test.cs
Last active October 6, 2016 05:17
Unity, goroutine-like csp, tests
using UnityEngine;
using System.Collections;
using Sa1;
public class CspTest : MonoBehaviour {
// Use this for initialization
void Start () {
csp.go(this, simple());
csp.go(this, timeout());
@5alamander
5alamander / DaisyChain.coffee
Last active October 17, 2016 03:06
chinese whispers game, daisy-chain in go, coffee/js-csp, erlang/elixir
csp.go ->
console.time 'daisy chain'
n = 100000
leftmost = csp.chan()
right = leftmost
left = leftmost
for i in [0...n]
right = csp.chan()
csp.go (left, right) ->
@5alamander
5alamander / csp.cs
Last active February 15, 2017 14:12
初版csp_for_unity。TODO: 1,处理异常时,在unity线程和系统线程处理方式不一致,2.系统线程中无法使用 timeout,3.外部无法手动停止系统线程中的某个coroutine,4.只使用了1个外部线程。更新:使用linkedlist替代queue,闲置时挂起线程。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
namespace Sa1 {
/// <summary>
/// ins: do not use timeout in the csp.subthread