Skip to content

Instantly share code, notes, and snippets.

@rjeli
rjeli / profit.hs
Created November 8, 2015 07:34
Hardcore DP
profit :: [Int] -> Int
profit xs = f (head xs) 0 (tail xs)
where
f minVal maxDiff [] = maxDiff
f minVal maxDiff (x:xs) = f (min minVal x) (max maxDiff (x - minVal)) xs
-- O(n) time, O(1) memory
// Set<Document> added
// Featurizer f
// sc::parallelize : List<T> -> JavaRDD<T>
Stream<Tuple2<Integer,Vector>> featurizedStream = added.stream()
.map(d -> new Tuple2(d.getId(), f.vector(d)));
JavaRDD<Tuple2<Integer,Vector>> featurized =
sc.parallelize(featurizedStream.collect(Collectors.toList()));
package com.eli.testproject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
List<Integer> nums = new ArrayList<>();
private class CountingLogger<T> implements Function<T, T> {
private int every;
private int count;
private Function<Integer,String> message;
public CountingLogger(int every, Function<Integer,String> message) {
this.every = every;
this.message = message;
this.count = 0;
inputs = [
'1 + 1',
'2 * 2',
'1 + 2 * 3',
'( 1 + 2 ) * 3'
]
def pemdas(s):
ops = { op: p for p, l in enumerate(['+-', '*/']) for op in l }
ostk = []

Keybase proof

I hereby claim:

  • I am rjeli on github.
  • I am rjeli (https://keybase.io/rjeli) on keybase.
  • I have a public key ASAcHZq4pvBCkWtaLl7lzqxAF1Uz7Hgr3flGCQswvhDefAo

To claim this, I am signing this object:

@rjeli
rjeli / main.cpp
Created August 24, 2019 00:43
freeing worker resources
// g++ -std=c++11 main.cpp -lpthread -o main && ./main
#include <iostream>
#include <thread>
#include <atomic>
#include <chrono>
class BackgroundTask {
public:
BackgroundTask() : done_(false),
worker_(&BackgroundTask::worker_main, this) {}
#!/usr/bin/env python3
import time
import evdev
from evdev import ecodes
SCROLL_FRAC = 0.1
if __name__ == '__main__':
devs = [evdev.InputDevice(path) for path in evdev.list_devices()]
dev = None
@rjeli
rjeli / solve.py
Last active March 29, 2024 19:40
DominoFit z3 solver
#!/usr/bin/env python3
import z3
import itertools
SIZE = 7
top = [2, 7, 4, 3, 6, 4, 5]
side = [6, 5, 2, 5, 6, 1, 6]
blacks = [
(0, 6), (1, 6), (2, 6),