Skip to content

Instantly share code, notes, and snippets.

View tlehman's full-sized avatar

Tobi Lehman tlehman

View GitHub Profile
@tlehman
tlehman / StreamMax.java
Created November 21, 2017 19:45
Comparing run times of computing a max int using a loop, Java 8 streams and parallel streams
package com.tobilehman.benchmarks;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class StreamMax {
public static void main(String args[]) {
StreamMax sm = new StreamMax(10_000_000);
Long then,now;
@tlehman
tlehman / AtomicIntegerExample.java
Created November 3, 2017 20:28
Atomic integer multithreaded example
import java.util.concurrent.atomic.AtomicInteger;
public class AtomicIntegerExample {
public static void main(String args[]) throws InterruptedException {
AtomicInteger a = new AtomicInteger();
NonAtomicInteger n = new NonAtomicInteger();
Runnable r = () -> {
for(int j = 0; j < 100_000; j++) {
a.getAndIncrement();
@tlehman
tlehman / times.sh
Created September 22, 2017 21:34
times script
#!/bin/sh
# This is used in bitbar to display the time in the two main timezones I work in:
TZ=America/Los_Angeles date +"%Y-%h-%d %r (%Z)" | sed 's/:[0-9][0-9] / /g'
TZ=UTC date +"%Y-%h-%d %r (%Z)" | sed 's/:[0-9][0-9] / /g'
# http://www.evanmiller.org/bayesian-ab-testing.html implemented in ruby
# requires the distribution gem from https://github.com/clbustos/distribution (gem 'distribution', require: false)
def probability_b_beats_a(completed_a, total_a, completed_b, total_b)
require 'distribution/math_extension'
total = 0.0
alpha_a = completed_a + 1
beta_a = total_a - completed_a + 1
alpha_b = completed_b + 1
@tlehman
tlehman / alice.xml
Last active June 20, 2016 03:50
alice TwiML
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice" language="en-US">Hello, the number you're calling is for existing and potential clients only.
If this is a sales call of any kind , including business to business please add this number to your do not call list and hang up now, otherwise, please press one to continue.</Say>
</Response>
@tlehman
tlehman / alice.xml
Created June 20, 2016 03:43
alice TwiML
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="alice" language="en">Hello, the number you're calling is for existing and potential clients only.
If this is a sales call of any kind , including business to business please add this number to your do not call list and hang up now, otherwise, please press one to continue.</Say>
</Response>
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Gather timeout="30" finishOnKey="1"
action="https://gist.githubusercontent.com/tlehman/6a01547faa90a790387f5bdc93d7cbfb/raw/ef8940e17a4560c9625c849706c019a9c7865893/forwards1.xml">
<Say>If you are a cold caller, please hang up. Otherwise, press 1 to continue.</Say>
</Gather>
</Response>
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Dial record="false">
+15038164076
</Dial>
</Response>
@tlehman
tlehman / backtracking_mkp.c
Last active April 18, 2016 21:25
Multiple knapsack problem solution using backtracking (with a smarter candidate generation function, and written in C)
/* Generate a sparse decision matrix using backtracking to solve the
multiple knapsack problem. In the code I use the term "bin" instead
of knapsack because I think "knapsack" is a dumb word. And sacks are
too flexible, bins are sturdier.
by @tlehman
Problem: There are N items and M bins. For each of the items, there is
a size, and for each bin, there is a capacity. We see an
assignment of each of the N items to at least one bin so that
@tlehman
tlehman / backtracking_mkp.c
Created April 18, 2016 21:00
Multiple knapsack problem solution using backtracking (with a smarter candidate generation function, and written in C)
/* Generate a sparse decision matrix using backtracking to solve the
multiple knapsack problem. In the code I use the term "bin" instead
of knapsack because I think "knapsack" is a dumb word. And sacks are
too flexible, bins are sturdier.
by @tlehman
Problem: There are N items and M bins. For each of the items, there is
a size, and for each bin, there is a capacity. We see an
assignment of each of the N items to at least one bin so that