Skip to content

Instantly share code, notes, and snippets.

View mboeh's full-sized avatar

Matthew Boeh mboeh

View GitHub Profile
@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 / tng-4x22.markdown
Last active November 20, 2016 19:00
TNG episode guide: 4x22, "Half A Life"
@mboeh
mboeh / symbol-gc.rb
Created March 8, 2015 06:29
symbol-gc.rb
puts "Ruby version: #{RUBY_VERSION}"
def show_a_sym(sym)
puts "sym #{sym} = #{sym.object_id}"
end
def pick_a_sym
a = (1..100_000).map{|s| :"dummy-#{s}" }
sym = a.sample
show_a_sym sym
@mboeh
mboeh / astar-room-search.rs
Last active August 29, 2015 14:09
rust astar experiments
extern crate astar; // from https://github.com/mboeh/astar.git
use std::vec::MoveItems;
#[deriving(Eq)]
#[deriving(Hash)]
struct Room<'a> {
id: int,
difficulty: int,
exits: Vec<&'a Room<'a>>
@mboeh
mboeh / 2wice.c
Last active August 29, 2015 14:08
#include <stdio.h>
#include <stdint.h>
extern int32_t twice(int32_t, int32_t(*)(int32_t));
int32_t dbl(int32_t x) {
/* x = arbitrary number here */
return x+x;
}
@mboeh
mboeh / Dockerfile
Last active August 29, 2015 14:08
mlton docker environment
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y build-essential libgmp10-dev curl
RUN curl -s -L http://downloads.sourceforge.net/project/mlton/mlton/20130715/mlton-20130715-1.amd64-linux.tgz | zcat - | tar x
WORKDIR /home
VOLUME /home