Skip to content

Instantly share code, notes, and snippets.

View takeshik's full-sized avatar

Takeshi KIRIYA takeshik

View GitHub Profile
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace TinyTweet
@takeshik
takeshik / get-attrs.cs
Created February 18, 2013 09:53
get Attribute[] from lambda
public static Attribute[] GetAttributes(Expression expr)
{
switch (expr.NodeType)
{
case ExpressionType.MemberAccess:
return Attribute.GetCustomAttributes(((MemberExpression) expr).Member);
case ExpressionType.Invoke:
return Attribute.GetCustomAttributes(((MethodCallExpression) expr).Method);
case ExpressionType.Index:
return Attribute.GetCustomAttributes(((IndexExpression) expr).Indexer);
public class TypeName
{
public String Namespace { get; set; }
public String[] HierarchicalNames { get; set; }
public override String ToString()
{
return String.Join("+", this.HierarchicalNames);
}
}
private static IEnumerable<Expression> TraverseImpl(Expression expression)
{
switch (expression.GetType().Name)
{
case "BinaryExpression":
return (expression as BinaryExpression).Let(e => new []
{
e.Conversion,
e.Left,
e.Right,
var dic = Enumerable.Range(char.MinValue, char.MaxValue)
.Select(i =>
{
Console.Clear();
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.Write((char) i);
return Console.CursorTop != 0 || Console.CursorLeft != 1
? Tuple.Create(i, Console.CursorLeft)
: null;
var cp932CharWidths = new Dictionary<Char, Byte>()
{
{'\u0007', 0},
{'\u0008', 0},
{'\u0009', 8},
{'\u000A', 0},
{'\u000D', 0},
{'\u00A2', 2},
{'\u00A3', 2},
{'\u00A7', 2},
void Main()
{
Make.Fix<int>(f => n => n < 2 ? 1 : f(n - 1) * n)(5).Dump(); // 120
}
public class Make
{
public static Func<T, T> Fix<T>(Func<Func<T, T>, Func<T, T>> func) { return Fun<T>.Fix(func); }
public static Func<T, T> Fix<T>(Func<Func<T, T>, Func<T, T>> func, T dummy) { return Fun<T>.Fix(func); }
private static class Fun<T>
@takeshik
takeshik / Error.cs
Created October 9, 2012 07:43
おかしい
public class ColumnData
{
public string Track;
public string Follow;
public string AccountName;
public string Tille;
public string Image;
public Column.StartType ColumnType;
public ColumnData Set(string _AccountName, string _Title, string _Track, string _Follow, Column.StartType Start)
{
@takeshik
takeshik / first.cs
Created September 19, 2012 15:02
複数のラムダ式から式木を構築する ref: http://qiita.com/items/438b845154c6c21fcba5
Expression<Func<int, int, bool>> expr1 = (x, y) => x * y < 20;
Expression<Func<int, int, bool>> expr2 = (x, y) => x + y == 8;
Expression<Func<int, int, bool>> expr = CombineLambda(expr1, expr2);
Console.WriteLine(expr.Compile()(3, 5)); // True
public static Expression<TDelegate> CombineLambda<TDelegate>(Expression<TDelegate> left, Expression<TDelegate> right)
{
// TODO: ここを埋めたい!
throw new NotImplementedException();
public IEnumerable<Expression> ReduceYield(SymbolTable symbols, Type expectedType)
{
Expression expression = this;
while (true)
{
Expression result;
if (expression is YacqExpression)
{
result = ((YacqExpression) expression).ReduceOnce(symbols, expectedType);
}