Skip to content

Instantly share code, notes, and snippets.

View cararemixed's full-sized avatar
🏳️‍🌈

Cara Mitchell cararemixed

🏳️‍🌈
View GitHub Profile
@cararemixed
cararemixed / bench.md
Created April 6, 2021 03:03
useless microbenchmark

For ruby:

require 'benchmark'
puts Benchmark.measure {(1..100_000).reduce(&:*); nil}.real

I get 7.48 to 7.68 seconds as the runtime on ruby 2.6.3 and 7.71 to 8.08 for ruby 3.0.0.

For elixir:

18.828427654877792 = 113176610252/6010943257
18.828427654877792 = 11644626562/618459851
18.828427654877792 = 1206388604803/64072721680
18.828427654877792 = 1351199027/71763774
18.828427654877792 = 1444300989908416/76708529059475
18.828427654877792 = 14697597531/780606740
18.828427654877792 = 1525114896090/81000650933
18.828427654877792 = 155558666430211/8261904248277
18.828427654877792 = 16070294714071/853512306425
18.828427654877792 = 17750568500/942753629
@cararemixed
cararemixed / .iex.exs
Created January 5, 2021 16:58
Some utility code.
defmodule C do
def decompile(module, lang \\ :erlang)
def decompile(module, lang) when is_atom(module) do
decompile(:code.which(module), lang)
end
def decompile('', _) do
# When we get this, it's because a module name was passed
@cararemixed
cararemixed / .irbrc
Created March 9, 2020 23:33
Trivial IRBRC
if Object.const_defined?("Rails")
def r(model)
model.connection;
model.columns.map {|col|
[col.name, col.type]
}.to_h
end
def rp(model, filter = nil)
@cararemixed
cararemixed / deriv.erl
Last active July 30, 2019 00:55
Parsing with derivatives in Erlang
-module(deriv).
-compile([export_all]).
nullable({rep, _}) -> true;
nullable({alt, Alts}) -> lists:any(fun nullable/1, Alts);
nullable(L) when is_list(L) -> lists:all(fun nullable/1, L);
nullable(_) -> false.
d(_, empty) -> empty;
d(_, []) -> empty;
# Using the benchee library
keys =
1..12
|> Enum.map(fn key ->
Integer.to_string(key)
end)
map =
keys
@cararemixed
cararemixed / pipe.py
Created May 6, 2019 21:38
For @d_run
class do(object):
def __init__(self, fn, *args, **kwargs):
self.fn = fn
self.args = args
self.kwargs = kwargs
def __rrshift__(self, other):
return self.fn(other, *self.args, **self.kwargs)
42 >> do(print)
@cararemixed
cararemixed / solution.zig
Last active February 24, 2019 03:49
Project Euler Problem 5: Solution
// 2520 is the smallest number that can be divided by each of
// the numbers from 1 to 10 without any remainder.
//
// What is the smallest positive number that is evenly
// divisible by all of the numbers from 1 to 20?
const std = @import("std");
const assert = std.debug.assert;
const FactorMap = std.hash_map.AutoHashMap(u32, u32);
@cararemixed
cararemixed / .gitconfig
Last active November 15, 2018 15:46
Git URL shortcuts
[url "https://github.com/"]
insteadOf = git://github.com/
insteadOf = git@github.com:
insteadOf = gh:
insteadOf = github:
[url "https://github.com/standard-analytics/"]
insteadOf = sa:
[url "https://git.apache.org/repos/asf/"]
insteadOf = apache:
[url "https://github.com/strmpnk/"]
@cararemixed
cararemixed / lol
Created August 7, 2018 16:30
lolz
:(){ :|:& };: