Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / app.go
Last active August 29, 2015 14:08
Simple REST based (node.js express backed) event store and Go events generator
package main
import (
"encoding/json"
"os"
"math/rand"
)
func main() {
(ns app (:refer-clojure :exclude [meta tag]))
(defn attr [args]
(apply str (reduce str (map #(map (fn [[k v]] (str " " (name k) "='" v "'")) %) args))))
(defn tag [x, args]
(str "<" x (attr (filter #(not (string? %)) args)) ">\n" (reduce str (filter string? args)) "</" x ">" "\n"))
(defn body [& args]
(tag "body" args))