Skip to content

Instantly share code, notes, and snippets.

@zacg
zacg / tp.go
Created July 7, 2014 19:27
HTM Temporal Pooler Example
package main
import (
"fmt"
"github.com/zacg/htm"
"github.com/zacg/htm/utils"
)
func main() {
tps := htm.NewTemporalPoolerParams()
@zacg
zacg / JsonNetValueProviderFactory
Created January 1, 2014 20:04
Json.net powered json value provider for asp.net mvc with fix for resetting the http request stream position before deserializing json.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Web.Mvc;
using System.IO;
using System.Globalization;
using System.Dynamic;
@zacg
zacg / SimpleTextAdapter
Created August 18, 2013 16:42
Simple Text Adapter For Xamarin ListViews
public class SimpleTextAdapter<T>
: BaseAdapter<T>
where T : new()
{
private T[] items;
private Activity context;
private Func<T,string> displayName;
private Func<T,long> itemId;
public SimpleTextAdapter(Activity context, T[] items, Func<T,string> displayName, Func<T,long> itemId)
@zacg
zacg / gist:6139955
Created August 2, 2013 13:38
Function for generating binary combinations
//Returns an array of boolean values representing
//every possible combination of n binary digits
function binaryCombos(n){
var result = [];
for(y=0; y<Math.pow(2,n); y++){
var combo = [];
for(x=0; x<n; x++){
//shift bit and and it with 1
if((y >> x) & 1)
combo.push(true);
@zacg
zacg / RevelJsonLowerExample
Last active December 20, 2015 11:39
Revel JSON result that outputs field names starting with lowercase.
func RenderLowerJson(o interface{}) revel.Result {
return RenderLowerJsonResult{o, true}
}
type RenderLowerJsonResult struct {
obj interface{}
lowerFirstChar bool
}
func (r RenderLowerJsonResult) Apply(req *revel.Request, resp *revel.Response) {