Skip to content

Instantly share code, notes, and snippets.

@kamyar1979
kamyar1979 / keybase.md
Created Apr 11, 2016
Keybase.io Prove!
View keybase.md

Keybase proof

I hereby claim:

  • I am kamyar1979 on github.
  • I am kamyar (https://keybase.io/kamyar) on keybase.
  • I have a public key whose fingerprint is 501C 5EE1 2BA0 8699 E154 4C69 3346 F754 C787 8090

To claim this, I am signing this object:

@kamyar1979
kamyar1979 / NumberReader.cs
Last active Feb 1, 2016
Read numbers (Persian)
View NumberReader.cs
namespace Extensions
{
using System;
using System.Text;
using System.Text.RegularExpressions;
/// <summary>
/// This class is in charge of reading numbers into culture specific text phrases.
/// </summary>
public static class NumberReader
@kamyar1979
kamyar1979 / CheckNull.cs
Last active Aug 29, 2015
CheckNull code for C# Expressions.
View CheckNull.cs
public static Expression<Func<T, T>> CheckNull<T>(Expression<Func<T, T>> expression)
{
var body = expression.Body as MemberInitExpression;
return Expression.Lambda<Func<T, T>>(AddCheckNull<T>(body, expression.Parameters[0]), expression.Parameters);
}
public static MemberInitExpression AddCheckNull<T>(MemberInitExpression expression, Expression parameter)
{
var memberParams = new List<MemberBinding>();
foreach (var item in expression.Bindings)
@kamyar1979
kamyar1979 / humanreadable.py
Created Oct 5, 2012
Python file size formatter
View humanreadable.py
def __repr__(self):
suf = 'BKMGTPEZY'
temp = self.size >> 10
index = 0
while temp:
temp >>= 10
index += 1
return '%g%s' % (round(float(self.size) / (1 << (10 * index)), 1), suf[index])
@kamyar1979
kamyar1979 / bzr_wsgi.py
Created Oct 1, 2012
Python script for making WSGI isapi for Bazaar DVCS smart server
View bzr_wsgi.py
from bzrlib.transport.http import wsgi
import sys
import os
import isapi_wsgi
if hasattr(sys, 'isapidllhandle'):
import win32traceutil
path_strip = 0 # Strip this many path elements off (when using url rewrite)
path_prefix = 0 # This many path elements are prefixes (depends on the
@kamyar1979
kamyar1979 / parseSize.cs
Last active Oct 10, 2015
Parse File Size string
View parseSize.cs
private long ParseSize(string size)
{
string factor = "KMGTPEZY";
if (Regex.IsMatch(size, @"^\d+$"))
{
return long.Parse(size);
}
else
{
@kamyar1979
kamyar1979 / DynamicJson.cs
Created Aug 28, 2012
A class for deserializing a single JSON string into a C# on-the-fly object.
View DynamicJson.cs
namespace DynamicJson
{
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
using System.Text.RegularExpressions;
public static class Json
{
@kamyar1979
kamyar1979 / pasterwsgi.py
Created Aug 21, 2012
Paste.Deploy general ISAIP-WSGI dll maker file for IIS.
View pasterwsgi.py
import os,sys
import isapi_wsgi
if hasattr(sys, "isapidllhandle"):
import win32traceutil
appdir = r'D:\Web\Rhodecode\\'
# The entry points for the ISAPI extension.
def __ExtensionFactory__():
from paste.deploy import loadapp
@kamyar1979
kamyar1979 / DynamicDictionary.cs
Created Aug 7, 2012
The famous, widely needed, DynamicDictionary class.
View DynamicDictionary.cs
namespace System.Dynamic
{
using System;
using System.Collections.Generic;
public class DynamicDictionary : DynamicObject
{
private Dictionary<string, object> items;
public DynamicDictionary()
@kamyar1979
kamyar1979 / DynamicTypeBuilder.cs
Created Aug 6, 2012
A class to for making a type dynamically.
View DynamicTypeBuilder.cs
namespace System.Dynamic
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
public class DynamicTypeBuilder
{
private AssemblyBuilder assemblyBuilder;