Skip to content

Instantly share code, notes, and snippets.

View lazamar's full-sized avatar

Marcelo Lazaroni lazamar

View GitHub Profile
@lazamar
lazamar / main.prof
Created July 3, 2024 11:15
Profile of compressor
Wed Jul 3 12:04 2024 Time and Allocation Profiling Report (Final)
main +RTS -p -RTS test ghcup
total time = 56.65 secs (56648 ticks @ 1000 us, 1 processor)
total alloc = 338,254,238,432 bytes (excludes profiling overheads)
COST CENTRE MODULE SRC %time %alloc
serialize.write Main Main.hs:(99,3)-(107,53) 27.6 27.7
@lazamar
lazamar / index.js
Last active March 15, 2024 15:49
Bubble sort and merge sort
// run with `node index.js`
function bubbleSort(list) {
for (let limit = 1; limit < list.length; limit++) {
for (let i = 0; i < list.length - limit; i++) {
let left = list[i];
let right = list[i + 1];
if (left > right) {
list[i] = right;
list[i+1] = left;
@lazamar
lazamar / Main.hs
Last active August 30, 2023 10:18
Unnecessarily knot tying solution to nested-map-reduce-traversal challenge.
{- Unnecessarily knot tying solution to https://github.com/josevalim/nested-map-reduce-traversal
You can run it with:
$ ghc Main.hs && ./Main
Which outputs:
Numbered 0 ("One",[Numbered 0 "A",Numbered 1 "B"])
Numbered 1 ("Two",[Numbered 2 "C",Numbered 3 "D",Numbered 4 "E"])
Numbered 2 ("Three",[Numbered 0 "F",Numbered 1 "G"])
Numbered 3 ("Four",[])
@lazamar
lazamar / Main.hs
Last active August 29, 2023 20:32
Solution to nested-map-reduce-traversal challenge.
{- This is a solution to https://github.com/josevalim/nested-map-reduce-traversal
without using explicit accumulators.
You can run it with:
$ ghc Main.hs && ./Main
Which outputs:
Numbered 0 ("One",[Numbered 0 "A",Numbered 1 "B"])
Numbered 1 ("Two",[Numbered 2 "C",Numbered 3 "D",Numbered 4 "E"])
Numbered 2 ("Three",[Numbered 0 "F",Numbered 1 "G"])
@lazamar
lazamar / mktags.sh
Last active November 14, 2023 21:46
Creating tags
#!/bin/bash
set -e
rm -f tags
find . -name "*.hs*" | fast-tags -
# ag respects .github
ag -l | ctags --optlib-dir=/home/lazamar/ --excmd=number --links=no -L- # This must be universal-ctags
@lazamar
lazamar / sshfs_cheatsheet.md
Created February 18, 2021 12:02
sshfs cheatsheet

Mounting

sshfs {user}@{host}:{path} {mounting_path} -o ServerAliveInterval=60 -o allow_other

MacOS unmount

umount -f {path}
@lazamar
lazamar / LongestSubsequences.hs
Created March 1, 2020 02:49
Longest Increasing Subsequence and Longest Common Subsequence
import Data.Function
import Data.List
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Map as Map
-- Longest increasing subsequence
-- O(nlogn)
lis :: Ord a => [a] -> [a]
lis = buildResult . snd . mapAccumL takeMax (Set.empty, Nothing)
module Lib where
import Data.List (foldr)
-- Complete the highestValuePalindrome function below.
highestValuePalindrome :: String -> Int -> Int -> String
highestValuePalindrome s n changesAllowed =
if changesToMakePalindrome > changesAllowed
then "-1"
@lazamar
lazamar / Hoogle stylesheet
Last active September 15, 2019 17:40
Make hoogle look nicer.
html {
/*background-color: #f5f5f5;*/
}
body {
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
}
a {
color: #E91E63;
}
p {
@lazamar
lazamar / better-git.sh
Last active December 17, 2018 12:14
Better Git log
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%Cgreen(%>(14)%cr) %C(bold blue)<%<(17,trunc)%an>%Creset %s %C(yellow)%d%Creset' --abbrev-commit"