Skip to content

Instantly share code, notes, and snippets.

View rsalgado's full-sized avatar

Roberto Salgado rsalgado

View GitHub Profile
@rsalgado
rsalgado / floyd-steinberg-dithering-example-color.markdown
Last active June 5, 2023 22:47
Floyd-Steinberg Dithering Example (Color)
@rsalgado
rsalgado / ascii-art-image-converter.markdown
Last active June 5, 2023 17:22
ASCII Art Image Converter
@rsalgado
rsalgado / sudoku_solver.py
Last active December 9, 2019 02:03
Sudoku solver implementation in Python
import copy
def peers(i, j):
row = set([(i, x) for x in range(9)])
column = set([(x, j) for x in range(9)])
start_row = 3 * (i // 3)
start_col = 3 * (j // 3)
square = set([
@rsalgado
rsalgado / sudoku_solver.exs
Last active September 24, 2019 01:57
Sudoku Solver in Elixir using pure functions and backtracking
# Sudoku Solver
#
# Go to the SudokuSolver module at the bottom to see the main module.
# To run the solver on a example input board, call `SudokuSolver.run/0`.
# The high-level backtracking logic is in the `SudokuSolver.solve/2` function;
# the other modules and their functions provide the supporting code for representing
# the board and performing simple tasks or providing utility functionality.
defmodule SudokuSolver.Cell do
@rsalgado
rsalgado / array_wrapper.exs
Created August 30, 2019 01:41
Small Elixir Wrapper of Erlang Arrays
defmodule ArrayWrapper do
@behaviour Access
defstruct erlang_array: :array.new()
@impl Access
def fetch(%ArrayWrapper{erlang_array: array}, key)
when is_integer(key) and (key >= 0) do
case :array.get(key, array) do
:undefined -> :error
@rsalgado
rsalgado / experimental_lisp_parser.js
Created June 14, 2019 23:08
Small attempt at a lisp parser
/*
Small and bare-bones Lisp parser and evaluator inspired by the respective problem posed at: https://www.recurse.com/pairing-tasks.
NOTE: This was my first time, as I had no previous experience with Lisp languages and only had some vague notions of them
besides the fact that their notation is prefix-based, so this implementation might not be totally correct.
This was just for the sake of learning and experimenting. And only implements four function: +, *, list and first.
*/
function tokenize(input) {
let validTokensRegExp = /(\w+|\(|\)|\+|\*)/g;
let tokens = input.match(validTokensRegExp);
@rsalgado
rsalgado / README.md
Last active August 17, 2020 13:27
SSE Handler Example with Plug and Cowboy 2

SSE Handler Example with Plug and Cowboy 2

To run in the console, without supervision trees, do the following:

$ iex -S mix

iex> Plug.Adapters.Cowboy2.http(NormalRouter, [], [dispatch: PlugDispatch.dispatch()])

To run inside a supervision tree, make sure to call child_spec (or use a tuple) with the correct arguments, like in the following example: