Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View kamyar1979's full-sized avatar

Kamyar Inanloo kamyar1979

View GitHub Profile
@kamyar1979
kamyar1979 / isapi_wsgi_web2py.py
Created November 8, 2011 11:26
Script for making wsgi isapi for web2py project.
import sys, os
if hasattr(sys, "isapidllhandle"):
import win32traceutil
sys.path.insert(0,'')
path=os.path.dirname(os.path.abspath('D:\\web2py\\gluon'))
if not path in sys.path: sys.path.append(path)
os.chdir(path)
@kamyar1979
kamyar1979 / DynamicTypeBuilder.cs
Created August 6, 2012 23:58
A class to for making a type dynamically.
namespace System.Dynamic
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
public class DynamicTypeBuilder
{
private AssemblyBuilder assemblyBuilder;
@kamyar1979
kamyar1979 / DynamicDictionary.cs
Created August 7, 2012 09:51
The famous, widely needed, DynamicDictionary class.
namespace System.Dynamic
{
using System;
using System.Collections.Generic;
public class DynamicDictionary : DynamicObject
{
private Dictionary<string, object> items;
public DynamicDictionary()
@kamyar1979
kamyar1979 / pasterwsgi.py
Created August 21, 2012 17:30
Paste.Deploy general ISAIP-WSGI dll maker file for IIS.
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 / DynamicJson.cs
Created August 28, 2012 12:22
A class for deserializing a single JSON string into a C# on-the-fly object.
namespace DynamicJson
{
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Text;
using System.Text.RegularExpressions;
public static class Json
{
@kamyar1979
kamyar1979 / parseSize.cs
Last active October 10, 2015 05:18
Parse File Size string
private long ParseSize(string size)
{
string factor = "KMGTPEZY";
if (Regex.IsMatch(size, @"^\d+$"))
{
return long.Parse(size);
}
else
{
@kamyar1979
kamyar1979 / bzr_wsgi.py
Created October 1, 2012 10:33
Python script for making WSGI isapi for Bazaar DVCS smart server
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 / humanreadable.py
Created October 5, 2012 01:28
Python file size formatter
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 / CheckNull.cs
Last active August 29, 2015 13:57
CheckNull code for C# Expressions.
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 / NumberReader.cs
Last active February 1, 2016 14:55
Read numbers (Persian)
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