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
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 / stack.py
Last active June 10, 2018 15:54
Simple sklearn-compatible class to stack models
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.model_selection import cross_val_predict
from sklearn.pipeline import make_union
from sklearn.model_selection._split import check_cv
from sklearn.utils.validation import check_X_y
class BlendedClassifierTransformer(BaseEstimator, TransformerMixin):
def __init__(self, clf, cv=3):
self.clf = clf
self.cv = cv
@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
(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))))
@caioaao
caioaao / common_config.clj
Last active February 14, 2020 15:57
buddy keys aero tagged literals
(ns common.config
(:require [aero.alpha.core :as aero.alpha]
[aero.core :as aero]
[clojure.java.io :as io]
[buddy.core.keys :as buddy.keys]))
(defn- rewrap [tl]
(fn [v] (tagged-literal (:tag tl) v)))
(defmethod aero.alpha/eval-tagged-literal 'priv-key
(load-extension "libfive-guile" "scm_init_libfive_modules")
(use-modules (libfive kernel) (libfive vec) (libfive csg) (libfive shapes) (libfive transforms))
(define test-shape
(difference
(sphere 1 #[0 0 0])
(cylinder-z 0.6 2 #[0 0 -1])
(reflect-xz (cylinder-z 0.6 2 #[0 0 -1]))
(reflect-yz (cylinder-z 0.6 2 #[0 0 -1]))))
(shape->mesh test-shape "out.stl" 10 '((-2 . 2) (-2 . 2) (-2 . 2)))