Skip to content

Instantly share code, notes, and snippets.

View xandkar's full-sized avatar
🤔
quis custodiet ipsos custodes?

Siraaj Khandkar xandkar

🤔
quis custodiet ipsos custodes?
View GitHub Profile
rq = read.table("~/Downloads/request_times.txt", header=FALSE)$V1
run_simulation = function(router_mode = "naive", reqs_per_minute = 9000, simulation_length_in_minutes = 5, dyno_count = 100) {
if(!(router_mode %in% c("naive", "intelligent"))) {
return("router_mode must be one of 'naive' or 'intelligent'")
}
reqs_per_ms = reqs_per_minute / 60000
simulation_length_in_ms = simulation_length_in_minutes * 60000
# you can make a text file of request times (in ms, one number per line) and import it here, or you can use a probability distribution to simulate request times (see below where setting req_durations_in_ms)
# rq = read.table("~/Downloads/request_times.txt", header=FALSE)$V1
# argument notes:
# parallel_router_count is only relevant if router_mode is set to "intelligent"
# choice_of_two, power_of_two, and unicorn_workers_per_dyno are only relevant if router_mode is set to "naive"
# you can only select one of choice_of_two, power_of_two, and unicorn_workers_per_dyno
run_simulation = function(router_mode = "naive",
reqs_per_minute = 9000,
run_simulation = function(router_mode = "naive",
reqs_per_minute = 9000,
simulation_length_in_minutes = 5,
dyno_count = 100,
choice_of_two = FALSE,
power_of_two = FALSE,
unicorn_workers_per_dyno = 0,
track_dyno_queues = FALSE) {
if(!(router_mode %in% c("naive", "intelligent"))) {
@xandkar
xandkar / state_space.ml
Created December 8, 2013 04:57
Make a complete multipartite graph of N symbolic state spaces.
module StateSpace :
sig
val enumerate : 'a list list -> 'a list list
val count : 'a list list -> int
val tests : unit -> unit
end = struct
open Printf
@xandkar
xandkar / riak-at-riot-games-talk-notes.md
Last active March 8, 2025 15:04
Notes on Riak at Riot Games talk

Notes on Riak at Riot Games talk

http://www.infoq.com/presentations/riak-game-scale

  • Data model challenges (14:25 - 25:00)
    • Complex queries - 2i
    • Conflict resolution
      • Redundant results for processing same data multiple time - LWW
      • Append-only data, like logs - set union of entries
  • aggregate stats, sets of counters - no way to resolve conflicts as is.
@xandkar
xandkar / gadt.ml
Last active January 3, 2016 07:09
Playing with GADTs
module type LANG =
sig
type 'a t
val eval : 'a t -> 'a
end
module L1 : LANG =
struct
type _ t =
$ python [17:44:25]
Python 2.7.5 (default, Jun 7 2013, 12:41:17)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> [x for x in range(1, 3)]
[1, 2]
>>>
>>> x
2
$ ocaml
# List.map (fun x -> let rec f x = match x with 0 -> 1 | n -> n * f (n - 1) in f x) [1; 2; 3];;
- : int list = [1; 2; 6]
#
let rec f x = match x with 0 -> 1 | n -> n * f (n - 1);;
val f : int -> int = <fun>
#
List.map f [1; 2; 3];;
- : int list = [1; 2; 6]
#

Is there a user-noticeable difference in how exceptions behave in SML vs OCaml?

Here're a couple of examples demonstrating the generative semantics of SML exceptions (derived from http://mlton.org/GenerativeException) followed by their analogues in OCaml:

1 in SML

@xandkar
xandkar / no_need_for_double_semicolons_in_source_files.ml
Created February 13, 2014 22:18
Demonstration of how to write OCaml source files so that no double semicolons are ever required
let print_line =
let line = String.make 80 '-' in
fun () -> print_endline line
module UglyA =
struct
open Printf
let x = 5;;