Skip to content

Instantly share code, notes, and snippets.

@zvkemp
zvkemp / cvim_config
Created January 28, 2019 18:25
cvim_config
site '*://*.github.com/*' {
unmap t
unmap k
set numerichints
}
@zvkemp
zvkemp / proxy.rb
Created August 31, 2018 16:52
protobuf-decoding server
#!/usr/bin/env ruby
# Requires `protoc` to be installed and available on PATH.
# See https://developers.google.com/protocol-buffers/
require 'bundler/inline'
require 'open3'
gemfile do
gem 'puma'
@zvkemp
zvkemp / parallel.exs
Created March 9, 2016 17:43
Annotated multi-process mapping module in Elixir
defmodule Parallel do
def map(enum, function, workers: n) do
worker_pool(n) # set up a worker pool
# lazily zip it together with the enum elements (result: [ { pid0, e0 }, { pid1, e1 } ... ])
|> Stream.zip(enum)
# send each piece of data to the worker, along with the mapping function
|> Enum.each(fn { pid, e } ->
send(pid, { e, function })
end)
@zvkemp
zvkemp / ruby_linked_list.md
Last active August 29, 2015 14:11
Functional Linked Lists in Ruby

As a Ruby-centric web developer, I am well-versed in Object-Oriented Design. It's a paradigm that serves its purpose well, but at times it can feel a bit insular. I feel it's difficult to completely understand how and why a system is put together the way it is without studying systems based on other paradigms. So around six months ago I set myself to the task of understanding functional programming. And looking back on my naive mid-2014 self, I would never have guessed how different pure FP really is, even compared to a function-heavy language like JavaScript.

I chose Haskell as my first functional language for several reasons — it's often regarded as the 'purest' functional language, it's deeply rooted in academia (so a lot of FP research is based on it), and it has a reasonably mature ecosystem. This article isn't about Haskell per se, though. It's meant to be a brief introduction to functional concepts presented in the familiar Ruby syntax. I'll use Haskell merely as a reference.

What follows is a soluti

module BinaryTree
class EmptyHashNode
def to_a
[]
end
def inspect
"{}"
end
require 'minitest/autorun'
require 'minitest/pride'
describe BinaryTree::HashNode do
let(:bt_hash){ BinaryTree::HashNode.new(:test, 100) }
specify { bt_hash[:test].must_equal 100 }
specify { bt_hash[:missing].must_be_nil }
specify "inserting a new value" do
# https://zvkemp.github.io/blog/2014/04/25/binary-search-trees-in-ruby/
module BinaryTree
class EmptyNode
def to_a
[]
end
def include?(*)
false
@zvkemp
zvkemp / tmux.conf
Last active December 25, 2015 12:49
tmux.conf
bind r source-file ~/.tmux.conf \; display "Reloaded!"
set -g default-terminal "screen-256color"
set -g status-left "#[bg=green]#[fg=blue,bold] #S #[default]"
set -g status-right "#[fg=black]%d %b %R "
set -g pane-border-fg blue
set -g pane-active-border-bg default
set -g pane-active-border-fg yellow