Skip to content

Instantly share code, notes, and snippets.

View caioaao's full-sized avatar
🏠
Working from home

Caio Oliveira caioaao

🏠
Working from home
View GitHub Profile
@caioaao
caioaao / boxplot_buys2.png
Last active June 22, 2017 20:06
Docs showing how to plot NMR buy prices
boxplot_buys2.png
@caioaao
caioaao / heal_conn.sh
Created November 13, 2017 21:37
Bash script for connection self-healing (to use on my raspberry pi/beaglebone)
#!/usr/bin/env bash
set -euo pipefail
HEARTBEAT_INTERVAL=3
EXPONENTIAL_BACKOFF_POWER=2
EXPONENTIAL_BACKOFF_MAX_TIMEOUT=60
EXPONENTIAL_BACKOFF_INITIAL_TIMEOUT=1
FROM tensorflow/tensorflow:1.4.0
ENV HOME /root
RUN echo 'export LC_ALL=C.UTF-8' >> /etc/profile
RUN echo 'export LANG=C.UTF-8' >> /etc/profile
RUN pip install enigma-catalyst
RUN jupyter nbextension enable --py --sys-prefix widgetsnbextension
@caioaao
caioaao / collisions.clj
Last active May 4, 2022 23:09
Solution to Nubank's collision exercise, in Clojure
(ns collisions.core
(:require [clojure.string :as str])
(:gen-class))
(defn str->edge [s]
(->> (str/split s #" ")
(map #(Integer/parseInt %))))
(defn file-contents->edges [s]
(->> (str/split s #"\n")
(ns aeron-cluster-test.core
(:require [clojure.stacktrace :refer [print-stack-trace]])
(:import [org.agrona CloseHelper]
[org.agrona.concurrent AgentTerminationException]
[org.agrona ExpandableArrayBuffer]
[org.agrona ErrorHandler]
[io.aeron.cluster ClusteredMediaDriver ConsensusModule ConsensusModule$Context]
[io.aeron.cluster.client EgressListener AeronCluster AeronCluster$Context ]
[io.aeron.cluster.service ClusteredService ClusteredServiceContainer ClusteredServiceContainer$Context Cluster ClusteredServiceAgent ClientSession]

PF.tv challenge

Let’s first write a function to check the outputs. Since it’s quite simple, I’ll use the example from the problem definition and a couple of corner cases:

(defn spy [x] (prn x) x)
@caioaao
caioaao / range_consolidation.clj
Created April 22, 2019 12:34
Solution for range consolidation challenge from purelyfunctional.tv newsletter
(ns caioaao.purely-functional.solutions.range-consolidation)
(defn ranges->events [vs]
(mapcat (fn [[a b]] [[:open a] [:close b]]) vs))
(def type->priority
{:open 1
:close 2})
;; since range includes both ends, `open` events have priority over `close`
@caioaao
caioaao / playground.clj
Last active January 29, 2020 14:53
state-flow stack trace
(ns playground
(:require [state-flow.core :as state-flow]
[state-flow.state :as state]))
(defn inc-a [s]
(update s :a inc))
(defn change-state []
(state/modify inc-a))
@caioaao
caioaao / core.clj
Created February 6, 2020 18:14
Testing garbage collection of keywords
(ns leak-test.core
(:gen-class))
(def alphanumerics (concat (map char (range (int \A) (inc (int \Z))))
(range 0 10)))
(defn random-alphanumeric-string [len]
"Generates a pseudo-random alphanumeric string"
(apply str (repeatedly len #(rand-nth alphanumerics))))