Skip to content

Instantly share code, notes, and snippets.

View mboeh's full-sized avatar

Matthew Boeh mboeh

View GitHub Profile
@mboeh
mboeh / README.markdown
Created July 19, 2012 23:23
Memoization and Threads

This shows how different approaches to memoization work (or don't) in different Ruby engines.

Synopsis

If you're using the idiomatic Ruby approach to memoization, like this:

def data
  @memo ||= expensive_action
end
@mboeh
mboeh / f__k.rb
Created February 13, 2021 23:29
playing with some styles for obfuscating text
class NoiseCensor
def initialize(chars = "&^%@*#")
@noise = chars.split(//).shuffle.cycle
end
def censor(text)
@noise.take(text.length).join
end
end
@mboeh
mboeh / damm.rb
Created November 14, 2018 04:05
toy implementation of damm algorithm
# https://en.wikipedia.org/wiki/Damm_algorithm
module Damm
extend self
OP_TABLE = [
[0, 3, 1, 7, 5, 9, 8, 6, 4, 2],
[7, 0, 9, 2, 1, 5, 4, 8, 6, 3],
[4, 2, 0, 6, 8, 7, 1, 3, 5, 9],
[1, 7, 5, 0, 9, 8, 3, 4, 2, 6],
@mboeh
mboeh / luhn.rs
Last active November 14, 2018 03:38
toy implementation of Luhn algorithm and credit card prefix check
use std::io;
use std::io::BufRead;
mod luhn {
pub fn luhn(cardn: &str) -> bool {
let chars : Vec<char> = cardn.chars().collect();
let mut sum = 0;
let len = chars.len();
for ridx in 1..=len {
@mboeh
mboeh / circuit.rb
Created May 28, 2018 07:32
circuit results
class Circuit
class OKResult
def initialize(value)
@value = value
end
def if_break(&blk)
self
require 'benchmark'
require "benchmark/memory"
N = 10_000_000
nonlazy = ->{ (1..N) .select(&:even?).map{|i| i*2 }.map{|i| i + 1 }.map(&:to_s).map(&:reverse).to_a.join(",").length }
lazy = ->{ (1..N).lazy.select(&:even?).map{|i| i*2 }.map{|i| i + 1 }.map(&:to_s).map(&:reverse).to_a.join(",").length }
one = ->{
(1..N).each_with_object([]) do |i,a|
if i.even?
@mboeh
mboeh / gist:4069267
Created November 14, 2012 00:02
social security
"the government borrows from it... the government could borrow more money to pay it back"
No it doesn't. No it couldn't. Please please PLEASE read up on the structure of the Social Security system before parroting the right-wing line on this. (Did you notice your link here was to an advocate of privatization?)
Social Security payments are made from the current year's Social Security tax. Any surplus collected is, by law, used to purchase (essentially) Treasury securities. This is intragovernmental debt -- it's money the government owes itself. It's actually a huge part of our current federal debt.
The federal government then goes on to spend that money on services like any other revenue. It could potentially sequester that revenue in a fund, but what would it invest it in? What form of savings is more reliable than Treasury securities? You can't just pile up money in a vault somewhere. So the government doesn't "borrow" from the Social Security Trust Fund -- the government's debt IS the Social Security T
@mboeh
mboeh / tng-4x22.markdown
Last active November 20, 2016 19:00
TNG episode guide: 4x22, "Half A Life"
@mboeh
mboeh / duplex_msg.c
Created November 29, 2013 00:44
C version of ZeroMQ experiment.
#include <czmq.h>
#include <bstrlib.h>
const char* shouter_addr = "inproc://shouter";
const char* listener_addr = "inproc://listener";
const char* ui_addr = "inproc://ui";
// Simulation Thread
typedef struct simulation_arg_t
require 'ffi-rzmq'
inport, outport, label = ARGV[0], ARGV[1], ARGV[2]
context = ZMQ::Context.new(1)
simulation = Thread.new do
shoutsock = context.socket(ZMQ::PAIR)
shoutsock.bind("inproc://shouter")