Skip to content

Instantly share code, notes, and snippets.

@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))
# name: Integral
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _upstream_count
echo (command git rev-list --count --left-right origin/(_git_branch_name)...HEAD ^/dev/null)
end
function _git_up_info
@butaji
butaji / changes.rb
Last active August 29, 2015 14:10
Generate changes by commits included in current TeamCity build
require 'net/http'
require 'json'
def get_json(uri)
url = URI.parse(uri)
req = Net::HTTP::Get.new(url, {'Accept' => "application/json"})
res = Net::HTTP.start(url.host, url.port) {|http|
http.request(req)
}
@butaji
butaji / App.java
Last active August 29, 2015 14:10
Serialize JSON to Map through GSON
import java.lang.reflect.Type;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
public class App {
public static void main(String[] args) {
String jsons = "{'appname':'Remoto', 'Version':'2.1', 'UUID':'agbd'}";
@butaji
butaji / lisp.rb
Last active August 29, 2015 14:13
Simple Lisp interpreter (lisp.rb) and Lisp front-end for Ruby (risp.rb; converting Lisp to Ruby primitives and after that evals it)
class Lisp
def ops(s)
if ([:+, :-, :*, :/, :>, :<, :>=, :<=, :==].include? s)
return lambda{|a, b| a.send(s, b) }
end
case s
when :first
return lambda{|x| x[0]}
# name: Agnoster
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for FISH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
## Set this options in your config.fish (if you want to :])
@butaji
butaji / WN725N.md
Created July 13, 2015 19:41
TP-Link TL-WN725N for Raspberry Pi
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);
}
}