Skip to content

Instantly share code, notes, and snippets.

View AndreFCruz's full-sized avatar
💻
Meeting deadlines

André Cruz AndreFCruz

💻
Meeting deadlines
View GitHub Profile
@AndreFCruz
AndreFCruz / testing-nan-bug.ipynb
Created May 5, 2024 12:02
Investigating a NaN bug on folktables
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AndreFCruz
AndreFCruz / main_thread_executor.py
Last active December 8, 2023 14:11
An executor that runs tasks on the main thread.
"""An executor that runs tasks on the main thread.
This can come in handy for debugging. For example, enables you to inspect and
set breakpoints on the underlying task, which is not easily done when using
separate threads.
Usually one would use this executor when the user provided `--n-jobs=0`.
"""
import logging
@AndreFCruz
AndreFCruz / condor_submit.py
Last active December 8, 2023 13:30
Helper to submit arbitrary executables to the HTCondor scheduler
#!/usr/bin/env python3
from __future__ import annotations
import sys
import random
import logging
from pathlib import Path
from datetime import datetime
from argparse import ArgumentParser
@AndreFCruz
AndreFCruz / caching.py
Last active October 25, 2023 11:14
A minimalist implementation of local caching to prevent re-running time-consuming function calls.
"""Utils for caching results.
"""
import json
import pickle
import logging
from pathlib import Path
from hashlib import sha256
import cloudpickle
@AndreFCruz
AndreFCruz / num_ways.py
Created January 27, 2019 13:55
Number of ways to climb a staircase with n steps, given a list of possible jumps.
"""
Given a number of steps _n_, and a list of possible _jumps_,
what's the number of different ways to climb the staircase ?
"""
def num_ways(n, jumps):
if n <= 1:
return 1
return sum([num_ways(n-j, jumps) for j in jumps if n-j >= 0])
@AndreFCruz
AndreFCruz / min_deletes_to_equalize.py
Last active January 11, 2019 15:25
Calculate minimum number of deletes needed for equalizing two strings.
#!/bin/python3
"""
Given two strings, s1 and s2, calculate the minimum number of deletions needed to make s1 == s2
For example: for the strings (AABAAB, ABAB) you need to delete two 'A's from the left string.
This is a variation of the longest subsequence problem.
"""
import os
import sys
@AndreFCruz
AndreFCruz / caffeine.lua
Last active March 28, 2021 09:01
My Hammerspoon configuration.
local obj = {}
obj.__index = obj
obj.menuBarItem = nil
function obj:start()
self.menuBarItem = hs.menubar.new()
self.menuBarItem:setClickCallback(self.clicked)
self.setDisplay(hs.caffeinate.get("displayIdle"))
@AndreFCruz
AndreFCruz / caffeine.lua
Last active June 2, 2018 12:50
My Hammerspoon configuration. Requires 'caffeine.lua' as seen below.
local obj = {}
obj.__index = obj
obj.menuBarItem = nil
function obj:start()
self.menuBarItem = hs.menubar.new()
self.menuBarItem:setClickCallback(self.clicked)
self.setDisplay(hs.caffeinate.get("displayIdle"))
@AndreFCruz
AndreFCruz / minimax.pl
Last active September 16, 2019 00:56
Prolog implementation of TicTacToe with MiniMax.
%% Code from http://www.emse.fr/~picard/cours/ai/minimax/#sec-3
% minimax(Pos, BestNextPos, Val)
% Pos is a position, Val is its minimax value.
% Best move from Pos leads to position BestNextPos.
minimax(Pos, BestNextPos, Val) :- % Pos has successors
bagof(NextPos, move(Pos, NextPos), NextPosList),
best(NextPosList, BestNextPos, Val), !.
minimax(Pos, _, Val) :- % Pos has no successors
@AndreFCruz
AndreFCruz / magic_squares.py
Created March 3, 2018 17:13
Solving the Magic Squares problem using constraint programming with Google's ortools.
# Solving Magic Squares using Google's ortools
# https://github.com/google/or-tools
from ortools.constraint_solver import pywrapcp
import sys
def main(n=4):
# Create the solver.
solver = pywrapcp.Solver('Magic square')
# declare variables