Skip to content

Instantly share code, notes, and snippets.

require 'java'
require 'observer'
require 'thread'
require 'pp'
include_class 'java.util.Random'
# port of deadgrid_refactor
class DeadGrid
attr_accessor :block_size, :grid, :width, :height
# encoding: UTF-8
# hey when is redis 2.8 coming out with clustering?
# I DON'T KNOW SO LET'S DO THIS HAPPY HORSE HOCKEY UNTIL THEN
require 'redis'
require 'redis/distributed'
r = Redis::Distributed.new [
'redis://box1:6379',
@squarism
squarism / debian_wheezy_one_true_way.sh
Last active December 17, 2015 02:39
Debian 7 dev box yak shaving instructions. Obviate productivity by messing with themes.
# omfg ocd dev box instructions incoming
# start with vanilla debian 7
# the cd installer doesn't give you a local mirror
# add these lines to the end of sources.list
# deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
# deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
sudo vi /etc/apt/sources.list
@squarism
squarism / rethinkdb_elastic_spike.rb
Created May 13, 2013 03:54
RethinkDB json store, using nobrainer ORM, automatically update elasticsearch index on save callback. This is fantastic.
require 'tire'
require 'nobrainer'
NoBrainer.connect 'rethinkdb://server/company'
class Employee
include NoBrainer::Document
field :name
field :title
@squarism
squarism / all_my_ruby_tricks.rb
Last active October 3, 2017 20:21
All my ruby tricks! All my secrets! Reveal thyself fool!
# Plot Twist: Does not contain all my Ruby Tricks <('‿'<)
# initialize a hash with empty array default value, on no key found, you can just push into a new array
hash = Hash.new {|h, k| h[k] = [] }
hash[:never_seen_before] << "asdf"
hash
# => {:never_seen_before => ["asdf"]}
# Default method options.
@squarism
squarism / forcing_oop_in.go
Created June 14, 2013 19:18
I'm pretty sure I'm writing unidiomatic go. But the official docs claim that structs work like OO classes do.
// You have to have your GOPATH and all that set up for this source file separation
// to work. I was playing with source file organization at the same time.
// If this is too annoying, I can rework it.
// car/car.go
package main
import (
@squarism
squarism / race_condition_example.rb
Last active December 19, 2015 18:18
Here's an example you can play with from José Valim's talk on concurrency. Set num_threads to anything above 1. Use jruby for maximum thread conflict chance.
# run me with jruby so that race conditions happen more frequently
# run with num_threads = 1 and then change num_threads to anything above 1.
# notice the difference? :D
num_threads = 1
require 'active_support'
class Counter
cattr_accessor :i
@squarism
squarism / advice.md
Last active December 20, 2015 15:19
Advice

Advice

Any advice, best practices or rules I run into. Mostly from reading new books.

The Way to Go (golang)

  • Use float64 for floating point numbers whenever possible, because all the functions of the math package expect that type.

Git

  • Rebase when you want a clean merging history. You can merge rebased feature branches and have the best of both worlds. When you are in a branch, rebase to the last commit of the develop or master branch (git rebase -i). Then squash all commits down (except first one). Commit it and it will prompt you for the commit message. Summarize all the commits to be the feature. Now merge like normal. The advantage here is that feature branches won't create long merge bubbles. It's a matter of taste really.
@squarism
squarism / keyboard_shortcuts.md
Last active December 20, 2015 15:19
Keyboard shortcuts

The All-Singing, All-Dancing Keyboard

Here's all the custom and normal keyboard shortcuts I use all the time. This is mostly for a Mac.

ZSH

In iTerm, set left alt to be +ESC

  • ALT + b - Move one word backward.
  • ALT + f - Move one word forward.
  • Ctrl-r - Search history, do this instead of up arrows, you'll make less mistakes when in a rush.
  • Ctrl-e/a - Move to beginning and end of line without deleting anything.
@squarism
squarism / after_seventy.txt
Created August 14, 2013 02:52
After Seventy
After Seventy
Read by Olive Higgins Prouty at her fiftieth reunion at Smith College.
PAMPER THE BODY
PROD THE SOUL
ACCEPT LIMITATIONS
BUT PLAY A ROLE
WITHDRAW FROM THE FRONT
BUT STAY IN THE FIGHT
AVOID ISOLATION