Skip to content

Instantly share code, notes, and snippets.

View eliascotto's full-sized avatar

Elia Scotto eliascotto

View GitHub Profile
@eliascotto
eliascotto / brainfuck.rs
Last active January 23, 2024 03:40
Brainfuck interpreter in Rust
use std::io::{self, Write};
struct Memory {
cells: Vec<i32>,
pointer: usize,
}
fn bf_runtime(m: &mut Memory, s: String) {
let instructions: &[u8] = s.as_bytes();
let mut idx: usize = 0;
@eliascotto
eliascotto / ants.clj
Created September 2, 2021 09:38
Rich Hickey Ants Simulator
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Copyright (c) Rich Hickey. All rights reserved.
;;
;; The use and distribution terms for this software are covered by the
;; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
;; which can be found in the file CPL.TXT at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;;
;; You must not remove this notice, or any other, from this software.
import { useRef } from "react";
export default function useThrottle(callback, delay) {
const savedTimer = useRef(null)
function execCallback(...args) {
// Create a timeout and block other calls until this callback is resolved
savedTimer.current = setTimeout(() => {
if (typeof callback === "function") {
callback(...args)
@eliascotto
eliascotto / DOMElementSelector.js
Last active July 18, 2021 06:28
DOM Element selector
/**
* UI to select any element on the webpage using the mouse,
* and print to console the exact selector of the DOM element.
*
* Inspired by Firefox Screenshot
*
* Live Version:
* https://codesandbox.io/s/dom-element-selector-dsm69
*/
(function () {
@eliascotto
eliascotto / scheduler.py
Created November 28, 2019 19:01
Airbnb Front End Engineer Interview
'''
Given a list of schedules, provide a list of times that are available for a meeting
Example input:
[
[[4,5],[6,10],[12,14]],
[[4,5],[5,9],[13,16]],
[[11,14]]
]
@eliascotto
eliascotto / gulpfile.js
Last active May 29, 2019 13:04
Gulp 4 config file for Jekyll
const path = require('path');
const child = require('child_process');
const browserSync = require('browser-sync');
const browserify = require('browserify');
const watchify = require('watchify');
const log = require('fancy-log');
const source = require('vinyl-source-stream');
const streamify = require('gulp-streamify');
const gulp = require('gulp');
@eliascotto
eliascotto / downloader.py
Last active July 18, 2021 06:30
"Best Artworks of All Time" dataset downloader for kaggle - https://www.kaggle.com/ikarus777/best-artworks-of-all-time
import os, sys
import json, re
import random
import wikipedia
from urllib import request
from time import sleep
import pandas as pd
MIN_SET = 31
MAX_SET = 118
@eliascotto
eliascotto / MathExpression.py
Last active April 8, 2021 06:35
Simple math parser for expressions evaluation in Python 3. Also includes a command line interface for use as a calculator.
'''
-> CONTEXT-FREE GRAMMAR <-
expr --> expr PLUS term | expr MINUS term | term
term --> term TIMES factor | term DIVIDE factor | factor
factor --> exponent POW factor | exponent
exponent --> MINUS exponent | final
final --> DIGIT | ( expr )
'''