Skip to content

Instantly share code, notes, and snippets.

@butaji
butaji / sim_c2.py
Created November 16, 2012 17:20
Turing-test N2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import urllib2
import time
import random
from multiprocessing import Pool
h1 = {
@butaji
butaji / hack.sh
Created July 31, 2012 20:13 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@butaji
butaji / Converter.cs
Created May 16, 2012 14:24
Typed converter
public abstract class TypedConverter<TFrom, TTo> : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is TFrom)
return Convert((TFrom)value);
return Convert(default(TFrom));
}
@butaji
butaji / Cache.cs
Created April 6, 2012 20:05
Simple C# cache helper
public class Cache
{
static readonly Dictionary<string, object> _cache = new Dictionary<string, object>();
public static T Run<T>(Func<T> func, params object[] prms)
{
var key = GetKey(func, prms);
if (!_cache.ContainsKey(key) || !(_cache[key] is T))
_cache.Add(key, func());
@butaji
butaji / checkin.sh
Created December 9, 2011 17:29
git-tfs checkin force
for i in {1..50}
do
git tfs checkin;
done
@butaji
butaji / checkin.sh
Created December 9, 2011 17:29
git-tfs checkin force
for i in {1..50}
do
git tfs checkin;
done
@butaji
butaji / method.cpp
Created October 30, 2011 18:55
AtomicLong.lazySet
bool GraphBuilder::append_unsafe_put_obj(ciMethod* callee, BasicType t, bool is_volatile) {
if (InlineUnsafeOps) {
Values* args = state()->pop_arguments(callee->arg_size());
null_check(args->at(0));
Instruction* offset = args->at(2);
#ifndef _LP64
offset = append(new Convert(Bytecodes::_l2i, offset, as_ValueType(T_INT)));
#endif
Instruction* op = append(new UnsafePutObject(t, args->at(1), offset, args->at(3), is_volatile));
compilation()->set_has_unsafe_access(true);
@butaji
butaji / singleton.cs
Created October 27, 2011 18:39
Sinlgeton<WTF>
public static class Singleton<T> where T : class
{
static volatile T _instance;
static object _lock = new object();
static Singleton()
{
}
public static T Instance
@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]
@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