Skip to content

Instantly share code, notes, and snippets.

@mmmries
mmmries / benchmark_roundtrips.exs
Created October 10, 2017 17:19
Gnat Benchmark Script
defmodule LatencyBenchmark do
@default_settings %{
num_actors: 1,
actions_per_actor: 1,
}
def benchmark(action_fn, settings) do # = num_actors, actions_per_actor, setup_fn, action_fn) do
settings = Map.merge(@default_settings, %{setup_fn: fn -> %{} end}) |> Map.merge(settings)
settings = Map.put(settings, :action_fn, action_fn)
{:ok, collector_pid} = Agent.start_link(fn -> [] end)
@mmmries
mmmries / 0-README.md
Last active August 10, 2017 20:35
protobuf benchmarking

Protobuf Benchmarking

A really basic protobuf benchmark comparing the protobuf encoding/decoding performance. For details please see the benchmark.rb file in this gist and check the gpb benchmark files.

Latest Results

  • protobuf-3.6.12
  • gpb-3.26.6
@mmmries
mmmries / quick_benchmark.exs
Created February 28, 2017 21:29
Quick benchmark tool for Elixir
quick_benchmark = fn(tcfn, tcn) ->
tc_l = :lists.seq(1,tcn) |> Enum.map(fn(_)-> tcfn |> :timer.tc |> elem(0) end)
tc_min = :lists.min(tc_l)
tc_max = :lists.max(tc_l)
tc_med = :lists.nth(round((tcn - 1) / 2), :lists.sort(tc_l))
tc_avg = round(Enum.sum(tc_l) / tcn)
%{min: tc_min, max: tc_max, median: tc_med, average: tc_avg}
end
# quick_benchmark.(fn() -> do_some_work() end, 1000) will do 1000 iterations of work and report median, average, min and max back to you in microseconds
@mmmries
mmmries / keybase.md
Created November 28, 2016 20:52
Keybase proof

Keybase proof

I hereby claim:

  • I am mmmries on github.
  • I am mmmries (https://keybase.io/mmmries) on keybase.
  • I have a public key whose fingerprint is 99B1 CC8A FE86 779F 3F7C 3D80 DA6C FBE7 2629 D9CF

To claim this, I am signing this object:

@mmmries
mmmries / temperatures.log
Last active March 25, 2016 05:50
Temperature Logging Sample
23:45:35.612 [debug] temperature update: {"/sys/bus/w1/devices/28-000007621b25/w1_slave", 21.625}
23:45:36.940 [debug] temperature update: {"/sys/bus/w1/devices/28-000007621b25/w1_slave", 21.625}
23:45:38.260 [debug] temperature update: {"/sys/bus/w1/devices/28-000007621b25/w1_slave", 21.625}
23:45:39.591 [debug] temperature update: {"/sys/bus/w1/devices/28-000007621b25/w1_slave", 21.687}
23:45:40.940 [debug] temperature update: {"/sys/bus/w1/devices/28-000007621b25/w1_slave", 21.687}
@mmmries
mmmries / CssHelper.js
Created March 16, 2016 16:35
Client Specific Colorschemes in Javascript
var ColorConversion = require('helpers/ColorConversion');
/**
Used for parsing all css rules on the document
object and replacing any default brand color
instances with the client's brand color scheme.
@class CssHelper
@example
```javascript
@mmmries
mmmries / MichaelRobotEntry.rb
Last active February 9, 2016 03:32
RRobotsEntry
require 'rrobots'
class MichaelRobotEntry
include Robot
INTERVAL = (3.14 * 2 * 100).to_i
def tick(events)
unless x < size && y < size
turn (135 - heading)
@mmmries
mmmries / README.md
Last active February 9, 2016 02:52
RRobots Tournament Instructions

First get the rrobots running locally on your machine by following the README on the repo.

Next make your own bot by making a file with the same name as the class that it defines (just like the examples/NervousDuck.rb defines the NervousDuck class).

Now put your bot into a gist and send a link to your gist to the person running the tournament.

@mmmries
mmmries / acts_as_csv.v1.rb
Created January 16, 2014 16:46
Convenient CSV My solution for the homework assignment from the end of chapter 2 in the [Seven Languages in Seven Weeks](http://pragprog.com/book/btlang/seven-languages-in-seven-weeks) book
module ActsAsCsv
def read
@csv_contents = []
filename = self.class.to_s.downcase + '.csv'
file = File.new(filename)
@headers = file.gets.chomp.split(', ')
file.each do |row|
@csv_contents << row.chomp.split(', ')
end
@mmmries
mmmries / request_spec.rb
Created June 13, 2013 21:14
rspec test that a request makes certain changes to a model. How can I do something like this?
describe "my request" do
it "should update the model" do
Model.any_instance.should_receive(:save) do
self.changes.should include(:attribute)
self.attribute.should == 'value'
end
xhr :put, model_path(model), {attribute: 'value'}
end
end