Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
jacaetevha / _README.textile
Last active August 29, 2015 14:25
Population Count functions

The population count function is used in many different scenarios. I first found out about it in the implementation of a HAMT data structure (Hash Array Mapped Trie).

The implementations herein are converted to Ruby from the C functions in this article. MRI is generally faster at these implementations than JRuby, but JRuby shines when any of these functions are called frequently enough to be able to inline the functions.

Platform information

OS Yosemite 10.10.4
Machine MacBook Pro (13-inch, Late 2011)
Processor 2.4 GHz Intel Core i5
Memory 16 GB 1333 MHz DDR3
@jacaetevha
jacaetevha / pharo
Created June 4, 2015 18:49
Enhancements to Pharo ZeroConf Bash scripts
#!/usr/bin/env bash
# some magic to find out the real location of this script dealing with symlinks
DIR=`readlink "$0"` || DIR="$0";
DIR=`dirname "$DIR"`;
cd "$DIR"
DIR=`pwd`
cd - > /dev/null
# disable parameter expansion to forward all arguments unprocessed to the VM
set -f
if [[ "$1" = "*.image" ]]; then
@jacaetevha
jacaetevha / track.sh
Last active March 3, 2016 01:19 — forked from ammojamo/track.sh
#!/bin/sh
input=
while true
do
input="$(/usr/bin/osascript 2>/dev/null <<-__HEREDOC__
with timeout of 300 seconds
tell application "System Events"
@jacaetevha
jacaetevha / designer.html
Created October 22, 2014 18:30
designer
<link rel="import" href="../topeka-elements/topeka-datasource.html">
<link rel="import" href="../topeka-elements/theme.html">
<link rel="import" href="../topeka-elements/topeka-resources.html">
<link rel="import" href="../topeka-elements/topeka-app.html">
<polymer-element name="my-element">
<template>
<style>
:host {
@jacaetevha
jacaetevha / story
Last active August 29, 2015 14:00
Pivotal Tracker Story Textalizer
#!/usr/bin/env ruby
require 'open-uri'
require "rexml/document"
TOKEN = ENV['TOKEN'] || '****'
PROJECT = ENV['PROJECT'] || '****'
STORY = ENV['STORY'] || ARGV[0]
# ripped from Rails
// XORCipher - Super simple encryption using XOR and Base64
//
// Depends on [Underscore](http://underscorejs.org/).
//
// As a warning, this is **not** a secure encryption algorythm. It uses a very
// simplistic keystore and will be easy to crack.
//
// The Base64 algorythm is a modification of the one used in phpjs.org
// * http://phpjs.org/functions/base64_encode/
// * http://phpjs.org/functions/base64_decode/
@jacaetevha
jacaetevha / setup-exercism-js
Created January 29, 2014 14:54
Given an exercism.io directory for JavaScript, edit the given spec file, create a test directory, and write the necessary node.js files.
#!/bin/bash
cat <<HERE > `pwd`/package.json
{
"dependencies": {
"underscore": "*"
},
"devDependencies": {
"jasmine-node": "*"
}
@jacaetevha
jacaetevha / database_cards.rb
Last active January 12, 2016 22:42
Prints (roughly) 5x7 cards on a standard 8.5x11 sheet of paper with the names of tables at the top, and columns of column data. The column data printed is just the name and its type. Column types have been abbreviated due to space constraints.
# This script creates blocks of text on 8.5x11 paper that is suitable for
# cutting and pasting onto 5x7 index cards. The blocks of text are descriptions
# of your Rails database tables. Specifically, it prints out a representation
# of the column type next to the name of a column for each table.
#
# It attempts to layout cards smartly so that large tables are handled with
# some gracefulness. For instance, this script was tested with tables that
# have as few as 3 columns and tables up to 134 columns. If a table has more
# columns in it than can be easily represented on one 5x7 index card, it will
# use a full 8.5x11 page.
@jacaetevha
jacaetevha / requests-by-dyno
Created October 3, 2013 04:42
Parses a Heroku log (defaults to /var/log/heroku, but you can pass it a log file as the first argument to the script), then prints out the dyno, the error code, the count, and the percentage of the total.
#!/bin/bash
# ---------------
# Example output:
# ---------------
# Dyno Count % of Total
# app[web.1] 103 14.33%
# app[web.2] 140 19.47%
# app[web.3] 111 15.44%
# app[web.4] 111 15.44%