Skip to content

Instantly share code, notes, and snippets.

View rdarder's full-sized avatar

Rafael Darder rdarder

  • Profitwell
  • Argentina
View GitHub Profile
@rdarder
rdarder / refcopy.go
Created February 6, 2012 19:11
array access references and copies
package main
import "fmt"
type foo struct {
val int
}
func main(){
arr := make([]foo, 5)
@rdarder
rdarder / gist:2884976
Created June 6, 2012 21:36
export changed files on git index to a temp folder, useful for a pre-hook that does linting
tmpdir=`mktemp -d`
tree=`git write-tree`
git archive $tree \
$(git diff --cached --name-status |
grep -v "^D" |
awk '{print $2}'
) |
tar xv -C $tmpdir
func TestRangeScan(t *testing.T) {
store := getLoadedStore()
testData.load()
sorted_words := sort.StringSlice(testData.words)
start, stop := sorted_words.Search("hello"), sorted_words.Search("world")
i := 0
fmt.Printf("scanning from %s to %s\n", start, stop)
for iter := store.Scan().From(str("hello")).To(str("world")).Start(); iter.Next(); i++ {
iter_word := iter.Entry().GetValue().(string)
word := testData.words[start+i]
@rdarder
rdarder / interval_test.go
Created December 19, 2013 15:24
benchmark passing structs vs pointers vs mixed (first level struct, second level pointer)
package smap
import (
"bytes"
"testing"
)
type skey string
func (s skey) Cmp(other Key) int {
@rdarder
rdarder / trigrams.py
Created October 23, 2014 21:53
Trigram text generator
import bisect
import collections
import random
import ply.lex as lex
import sys
import time
tokens = (
'NUMBER',
'WORD',
from itertools import islice, chain
import random, sys, collections, bisect
def index(words, queue):
"""
Generate a prefix index for an input word sequence.
The prefix length is the queue length.
The index tracks suffixes and following words, taking frequency into account.
The output index will contain, for each suffix, an ascending tuple of
@rdarder
rdarder / ping.go
Created November 2, 2014 04:18
Go-endpoints default values annotations
/* app.yaml
application: ping
version: 1
runtime: go
api_version: go1
handlers:
- url: /_ah/spi/.*
script: _go_app
@rdarder
rdarder / self_reference_fk.py
Created February 19, 2015 14:33
Self reference foreign key example. Test to check if mysql and sqlite supported DEFERRED constraint checks, turns out not.
from sqlalchemy import Column, Integer, ForeignKey, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, Session
Base = declarative_base()
class Person(Base):
__tablename__ = 'persons'
id = Column(Integer, primary_key=True)
@rdarder
rdarder / turnstiles.go
Last active August 29, 2015 14:20
ornamental gardens, failing turnstiles
package main
import "fmt"
var counter = 0
func turnstile(turns int, done chan bool){
for i := 0; i < turns; i++{
counter = counter + 1
}
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<polymer-element name="my-element">