Skip to content

Instantly share code, notes, and snippets.

View leodutra's full-sized avatar
🦙
Llama and other LLMs

Leo Dutra leodutra

🦙
Llama and other LLMs
View GitHub Profile
@leodutra
leodutra / waitToDisappear.swift
Last active March 27, 2020 05:44
waitToDisappear Swift UI Test
func waitToDisappear(_ element: XCUIElement, timeout: TimeInterval) -> Bool {
let startTime = Date().timeIntervalSinceReferenceDate
let remainingTime = { () -> Double in
let diff = timeout - (Date().timeIntervalSinceReferenceDate - startTime)
return diff > 0 ? diff : 0
}
repeat {
if !element.exists || !element.isHittable {
return true
}
@leodutra
leodutra / waitForHittable.swift
Created March 27, 2020 02:02
waitForHittable Swift UI Test
static func waitForHittable(_ element: XCUIElement, timeout: TimeInterval) -> Bool {
let startTime = Date().timeIntervalSinceReferenceDate
let remainingTime = { () -> Double in
let diff = timeout - (Date().timeIntervalSinceReferenceDate - startTime)
return diff > 0 ? diff : 0
}
if element.waitForExistence(timeout: remainingTime()) {
repeat {
if element.isHittable {
return true
@leodutra
leodutra / reducer-lib.js
Last active February 26, 2020 06:08
Reducer library for JS
const sumReducer = (sum, x) => sum + x;
const minReducer = (min/* =null */, x) => {
if (min == null) return x;
return min < x ? min : x;
};
const maxReducer = (max/* =null */, x) => {
if (max == null) return x;
return max > x ? max : x;
};
@leodutra
leodutra / ThinkAboutMonads.md
Created January 10, 2020 05:50 — forked from brayoh/ThinkAboutMonads.md
How to think about monads

How to think about Monads

Initially, Monads are the biggest, scariest thing about Functional Programming and especially Haskell. I've used monads for quite some time now, but I didn't have a very good model for what they really are. I read Philip Wadler's paper Monads for functional programming and I still didnt quite see the pattern.

It wasn't until I read the blog post You Could Have Invented Monads! (And Maybe You Already Have.) that I started to see things more clearly.

This is a distillation of those works and most likely an oversimplification in an attempt to make things easier to understand. Nuance can come later. What we need when first learning something is a simple, if inaccurate, model.

This document assumes a beginner's knowledge of pure functional programming and Haskell with some brief encounters of Monads, e.g. [Functors, Applicatives, And

@leodutra
leodutra / kernel.js
Created November 26, 2019 22:46 — forked from Carreau/kernel.js
A node.js kernel for IPython notebook. You can see the explanation of the ipynb rendered in http://nbviewer.ipython.org
zmq = require("zmq")
fs = require("fs")
var config = JSON.parse(fs.readFileSync(process.argv[2]))
var connexion = "tcp://"+config.ip+":"
var shell_conn = connexion+config.shell_port
var pub_conn = connexion+config.iopub_port
var hb_conn = connexion+config.hb_port
@leodutra
leodutra / how-much-water-per-day.js
Last active September 8, 2022 04:12
How much water should you drink per day? ( JavaScript )
// WARNING!
// Water Intoxication.
// This is rare but it can happen.
// What happens is that when too much water enters the cells, the tissues swell.
// This causes an electrolyte and salt imbalance which can cause irregular heart
// beat and allow fluid to enter the lungs.
// The pressure due to swelling will also put pressure on the brain and nerves,
// which can also cause problems.
// Swelling in the brain can cause coma, seizures, and even death.
@leodutra
leodutra / fast-array.js
Created October 23, 2019 04:54
Fast/elastic array for bad JavaScript engines ( FastArray )
'use strict';
// TODO implement .splice()
// TODO implement .reduce()
// TODO implement .indexOf()
// TODO implement .lastIndexOf()
// TODO implement ECMA5+ <Array> functions
@leodutra
leodutra / .zshrc
Last active April 19, 2022 15:02
.zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/home/home/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
@leodutra
leodutra / -setup-linux-devenv.md
Last active April 4, 2024 05:38
Install and Setup Ubuntu Linux dev env with Terminator, ZSH (+ .zshrc) + Oh My Zsh + Powerlevel9k + plugins, Rust, FNM + VSCode (+ext) and Nerd Font

Setup Ubuntu Linux Dev Environment

Terminator, ZSH (+ .zshrc) + Oh My Zsh + Powerlevel9k + plugins, Rust, FNM + VSCode (+ext) and Nerd Font

To setup Linux for WSL2, see this gist

Preview

Requirements

@leodutra
leodutra / -setup-windows-wsl-devenv.md
Last active April 5, 2024 23:44
Install and Setup Windows Subsystem 2 for Linux, Hyper, ZSH + Oh My Zsh + Powerlevel9k + plugins, FNM + VSCode (+ext) and Nerd Font

Setup Windows Subsystem 2 for Linux

Windows Subsystem 2 for Linux, Hyper, ZSH + Oh My Zsh + Powerlevel9k + plugins, FNM + VSCode (+ext) and Nerd Font

To setup native Linux, see this gist

Preview

Requirements