Skip to content

Instantly share code, notes, and snippets.

Avatar

Matthew Boeh mboeh

View GitHub Profile
@mboeh
mboeh / f__k.rb
Created Feb 13, 2021
playing with some styles for obfuscating text
View f__k.rb
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 Nov 14, 2018
toy implementation of damm algorithm
View damm.rb
# 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 Nov 14, 2018
toy implementation of Luhn algorithm and credit card prefix check
View luhn.rs
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
circuit results
View circuit.rb
class Circuit
class OKResult
def initialize(value)
@value = value
end
def if_break(&blk)
self
View lazy-bm.rb
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 Nov 20, 2016
TNG episode guide: 4x22, "Half A Life"
View tng-4x22.markdown
View 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 Aug 29, 2015
rust astar experiments
View astar-room-search.rs
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>>
View 2wice.c
#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 Aug 29, 2015
mlton docker environment
View Dockerfile
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