Skip to content

Instantly share code, notes, and snippets.

@bcc32
bcc32 / streams.scm
Created May 12, 2016 11:39
The classic Haskell example in Scheme
(define-syntax stream-cons
(syntax-rules ()
((_ h t)
(cons h (delay t)))))
(define stream-car car)
(define (stream-cdr stream)
(force (cdr stream)))
(define stream-nil '())
@bcc32
bcc32 / bf.rb
Created January 7, 2017 22:33
Brainfuck-C transpiler in Ruby
#!/usr/bin/env ruby -w
program = ARGF.read.tr('^[],.<>+-', '')
c_program = []
label_counter = -1
labels = []
program.each_char do |c|

Keybase proof

I hereby claim:

  • I am bcc32 on github.
  • I am a2z (https://keybase.io/a2z) on keybase.
  • I have a public key ASA4OFR9t5JwEofDtkO4QsNCEGvpY-iF2JVUPuQaetCRwQo

To claim this, I am signing this object:

@bcc32
bcc32 / template.cc
Created October 3, 2017 04:35
Competition Programming starter template
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
@bcc32
bcc32 / main.ml
Created October 7, 2017 11:38
OCaml 4.04.2 Compiler Bug
module type Int = sig
val one : int
val (+) : int -> int -> int
end
module Make (Int : Int) = struct
(* this assertion must fail in order to make the linker command fail *)
let () = assert false
(* this assertion doesn't matter *)
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFN98KEBCACmtmyQDSG2u5WoQ1Bxk/D4+S/SZ2oXpoT9uraT5whibBt0ecMA
mA+Z1gaIEV5cTcWvRlCmCLTDYXDuSB8Otnq1BDBBWDDzXCEYUCIbVqLUVgyotv8b
VuStaiNcmZL3aiE+anrThm6XVmtB2TBBieFHAbienR4+bsqLydB1OW/LJzbKNKID
BG4rVAlcHVJzfBm2bt5C6usC0FqhMEKIRoQOYwKe9qW/817PNwb4NVY8KyZA49Ku
R9Wc3emuvThu9NCMGJI8bSuZW11PtSyda4ex0hXyQaX69TgffG0avwTjz1esAQfS
rUEw54TbKmdaTbd/TbzEK5qi1F5oV8E94ls9ABEBAAG0JkFhcm9uIEwuIFplbmcg
PHplbmcuYWFyb24ubEBnbWFpbC5jb20+iQE8BBMBCAAmAhsDBwsJCAcDAgEGFQgC
CQoLBBYCAwECHgECF4AFAlifd3QCGQEACgkQtoMMVkrXRYR+awgAnBuepcYlTBT2
@bcc32
bcc32 / rename-to-mtime.pl
Created June 22, 2018 06:55
A simple perl script to rename files based on their modification times.
use 5.016;
use warnings;
use autodie;
use File::Spec;
use File::stat;
use POSIX qw(strftime);
# rename_noclobber($old, $new);
#
@bcc32
bcc32 / not_quite_open_recursion.ml
Last active July 16, 2019 02:37
Openly recursive module shenanigans
module Greeter = struct
type t = unit
let create () = ()
let addressee _t = "World"
let greet _t = "Hello, " ^ addressee _t
end
module Name_greeter = struct
type t = { name : string }
@bcc32
bcc32 / bench_map_length.ml
Last active September 5, 2019 21:06
Benchmark of Map.length between OCaml stdlib and Jane Street Base/Core
(* https://discuss.ocaml.org/t/efficiently-checking-if-map-set-is-singleton/1611/2 *)
open! Core
open Core_bench
let bench = Bench.Test.create_indexed ~args:[ 1; 10; 100; 1000; 10_000 ]
module type Map = sig
type 'data t
@bcc32
bcc32 / keep-synced.rb
Created November 22, 2021 23:09
Keep directories synced
require 'pathname'
src = ARGV[0]
dst = ARGV[1]
src = "#{src}/" unless src.end_with?("/")
dst = "#{dst}/" unless dst.end_with?("/")
src = Pathname.new(src)
dst = Pathname.new(dst)