Skip to content

Instantly share code, notes, and snippets.

View mbergal's full-sized avatar

Misha Bergal mbergal

View GitHub Profile
@mbergal
mbergal / gist:895860
Created March 31, 2011 05:23
Contexts in Python
def define_context( context, parent_contexts = None, verbose = False ):
if verbose:
print 'Defining context for \"%s\"' % context.__name__
if parent_contexts is None:
parent_contexts = []
def make_test_case_name( parent_contexts, context ):
if len(parent_contexts) > 0:
return '_'.join( [ x.__name__ for x in parent_contexts + [ context ] ] )
@mbergal
mbergal / gist:1130818
Created August 7, 2011 21:35
Array or args?
function foo( args )
{
if( !(promises instanceof Array) )
args = Array.prototype.slice.call(arguments);
...
}
@mbergal
mbergal / speclite.cs
Created October 3, 2011 08:06
RSpec like testing framework for .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SpecLite
{
class Suite
{
@mbergal
mbergal / SingleThreadedSynchronizationContext.cs
Created February 10, 2012 08:15
SingleThreadedSynchronizationContext
class SingleThreadedSynchronizationContext : SynchronizationContext
{
private readonly Queue<Action> messagesToProcess = new Queue<Action>();
private readonly object syncHandle = new object();
private bool isRunning = true;
public override void Send(SendOrPostCallback codeToRun, object state)
{
throw new NotImplementedException();
@mbergal
mbergal / gist:2014754
Created March 11, 2012 02:52
STDEV of Putin's result
select distinct vp.ParentId, stdev( vr.Percents ) over (partition by vp.ParentId ) dev ,
( select FullName from VotingPlace where Id = vp.ParentId )
from VotingResult vr inner join VotingPlace vp on vr.VotingPlaceId = vp.Id where vr.Counter = '23' and vp.ElectionId = 'PRES2012' and vp.Type = 5
order by dev desc
@mbergal
mbergal / gist:2318074
Created April 6, 2012 08:10
Find conflicting assembly references. Port of https://gist.github.com/1673952 to PowerShell
param(
[Parameter(Mandatory=$true)][string] $binPath
)
function GetAllAssemblies( [string] $path )
{
$assemblyFiles = Get-ChildItem $path | Where-Object { $_.Extension -eq '.dll' -or $_.Extension -eq '.exe' }
$assemblies = $assemblyFiles | %{
try {
[System.Reflection.Assembly]::LoadFile( $_.FullName )
@mbergal
mbergal / gist:2511202
Created April 27, 2012 17:50
Serializing EF entities
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
@mbergal
mbergal / a.py
Created July 30, 2012 04:38
Python stack trace
def foo():
bar()
def bar():
raise Exception( "test" )
foo()
@mbergal
mbergal / a.rb
Created July 30, 2012 04:39
Ruby stack trace
def foo
bar()
end
def bar
raise "test"
end
foo()
@mbergal
mbergal / a.js
Created July 30, 2012 04:40
Node stack trace
function foo()
{
bar()
}
function bar()
{
throw new Error( "test" )
}