Skip to content

Instantly share code, notes, and snippets.

public Dictionary<string, object[]> CompareObjects<T>(T obj1, T obj2)
{
var result = new Dictionary<string, object[]>();
typeof(T)
.GetProperties()
.Select(p => new { p.Name, Val1 = p.GetValue(obj1, new object[] { }), Val2 = p.GetValue(obj2, new object[] { }) })
.Where(i => i.Val1 != i.Val2)
.ToList()
.ForEach(p => result.Add(p.Name, new[] { p.Val1, p.Val2 }));
public class PrettyPrinterWithNeq : PrettyPrinter
{
public override string PrettyPrint(Expr that)
{
var n = that as Neg;
if (n != null) return "-(" + PrettyPrint(n.operand) + ")";
return base.PrettyPrint(that);
}
}
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Поиск по узлу
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
function loadFormWithHash() {
$.get('<%= Url.Action("SearchForm","Person") %>?' + window.location.hash.slice(1),
function (data) {
$('#searchContainer').html(data);
@butaji
butaji / bundles.sh
Created April 24, 2011 19:41 — forked from mads-hartmann/bundles.sh
This is how I manage my textmate bundles.
#
# This script will install the following Textmate bundles
#
# Languages
# - c https://github.com/textmate/c.tmbundle
# - coffeescript https://github.com/jashkenas/coffee-script-tmbundle
# - context free https://github.com/textmate/context-free.tmbundle
# - erlang https://github.com/textmate/erlang.tmbundle
# - haskell https://github.com/textmate/haskell.tmbundle.git
# - html https://github.com/textmate/html.tmbundle
@butaji
butaji / server.hs
Created May 29, 2011 20:27
Simple Haskell web server
import Control.Monad
import Data.Char
import System.IO
import Network
import Data.Time.LocalTime
data RequestType = GET | POST deriving (Show)
data Request = Request { rtype :: RequestType, path :: String, options :: [(String,String)] }
data Response = Response { version :: String, statuscode :: Int }
@butaji
butaji / guids.js
Created August 12, 2011 10:42
JavaScript GUID generator
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
@butaji
butaji / moscow_weather
Created September 3, 2011 23:52
Yahoo weather image for Moscow
curl -o /tmp/weather.html http://weather.yahoo.com/russia/moskva/moscow-2122265/;
curl -o /tmp/currenttemp.png `grep 'div class="forecast-icon" style="background:url(' /tmp/weather.html | awk -F"'" '{ print $2 }'`
@butaji
butaji / kill_em_all.ps1
Created September 6, 2011 17:03
Uninstall all SharePoint solutions
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell
$spAdminServiceName = "SPAdminV4"
Stop-Service -Name $spAdminServiceName
$deployedSolutions = Get-SPSolution | Where-Object {$_.Deployed -eq $true}
if($deployedSolutions)
{
foreach($solution in $deployedSolutions)
@butaji
butaji / gist:1208599
Created September 10, 2011 18:17
Download all files from url with wget
wget -r -l1 -A.mp3 <url>
#http://techpatterns.com/forums/about894.html
@butaji
butaji / usd_rub.py
Created October 2, 2011 18:24
maximum subarray of currency usd to rub for 5 years
import csv
def find_crossing(a, low, mid, high):
max_left = 0
max_right = 0
left_sum = -1e308
sum = 0
for i in range(mid, low, -1):
sum = sum + a[i][1]