Skip to content

Instantly share code, notes, and snippets.

View tanema's full-sized avatar
🐦

Tim Anema tanema

🐦
View GitHub Profile
@tanema
tanema / hershey.go
Created March 30, 2022 15:52
The most simple threadsafe progress bar in go
package hershey
import (
"fmt"
"math"
"strings"
"sync"
"time"
)
@tanema
tanema / multiprocess_migration.sh
Last active March 4, 2022 09:23
migrate files from gridfs to aws s3
#! /bin/bash
###################### USAGE ######################################
usage() {
echo "
Usage: mongotos3 [-t n] mongo_host mongo_collection s3_bucket
-t : number of parallel processes to use
mongo_host : the host of the mongodb server
mongo_collection : the collection to collecthe gridfs data from
s3_bucket : the name of the bucket you want to cp the files to
"
@tanema
tanema / example.rb
Last active May 26, 2021 18:22
Create a local key value store using only the standard library in ruby
require 'localstore'
DB.set(key: "value")
DB.exists?(:key) # => true
DB.get(:key) # => "value"
DB.get(:other, "default value") # => default val
DB.get(:other) do
val = computed_val()
DB.set(other: val)
val
@tanema
tanema / id_fuzzing.go
Created July 28, 2020 00:15
If you need a displayable ID but do not want to generate an ID with uniqueness constraints and try and get it into the database without breaking everything, try just encrypting your ID so that it looks like a nice visible ID but also without your secrets it cannot be reverse engineered to the original ID. See it here https://play.golang.org/p/Em…
package main
import (
"fmt"
"strconv"
"strings"
)
const (
// These are secret random numbers that are meant to help encrypt and disguise
@tanema
tanema / cookielistener.js
Created August 21, 2012 14:08
cookie listener for changes
function cookieListener(cookieName, callback) {
this.cookiename = cookieName;
this.callback = callback;
this.cookieRegistry = [];
this.interval = setInterval(this.observe, 100);
}
cookieListener.prototype.CREATED = 'created';
cookieListener.prototype.DELETED = 'deleted';
cookieListener.prototype.UPDATED = 'updated';
cookieListener.prototype.observe = function() {

Keybase proof

I hereby claim:

  • I am tanema on github.
  • I am timanema (https://keybase.io/timanema) on keybase.
  • I have a public key ASB-TL0sgWCQjhi74q_peFJTNo2FDEgs3llgDLu6uQr1VAo

To claim this, I am signing this object:

@tanema
tanema / chat-client.go
Created October 3, 2013 16:47
distributed chat client made for a golang hack night, it can both send and receive messages
package main
import (
"fmt"
"flag"
"net"
"bufio"
"os"
"time"
"strconv"
@tanema
tanema / git-type-loc.sh
Created May 27, 2013 19:38
Get the number of lines of code by extension, on a git repo.
git ls-files | perl -pe "s/.*\.(.*?)\n/\.\1\n/" | awk '/\..*/' | sort | uniq | xargs -n1 -E '\n' -I % sh -c 'git ls-files "*%" | xargs cat | echo "$(wc -l) %"' | sort -rn
@tanema
tanema / gist:3445133
Created August 24, 2012 03:27
Ember trigerable text field so when enter button is pressed an action is called
ABApp.TriggerableTextField = Ember.TextField.extend(Ember.TargetActionSupport, {
insertNewline: function() {
this.triggerAction();
}
});
@tanema
tanema / vimrc
Created August 21, 2012 14:11
my vimrc file
set nocompatible " use vim defaults
set mouse=a " use mouse because I am a noob
set ls=2 " allways show status line
set tabstop=2 " numbers of spaces of tab character
set shiftwidth=2 " numbers of spaces to (auto)indent
set scrolloff=3 " keep 3 lines when scrolling
set showcmd " display incomplete commands
set hlsearch " highlight searches
set incsearch " do incremental searching
set ruler " show the cursor position all the time