Skip to content

Instantly share code, notes, and snippets.

View turboMaCk's full-sized avatar
🏠
Working from home

Marek Fajkus turboMaCk

🏠
Working from home
View GitHub Profile
@turboMaCk
turboMaCk / Partition.hs
Created April 24, 2024 14:39
Tail recursion example
{-# LANGUAGE LambdaCase #-}
module Partition (main) where
-- original implementation
partitionMaybe' :: (a -> Maybe b) -> [a] -> ([(a, b)], [a])
partitionMaybe' f = go
where
go = \case
[] -> ([], [])
(head : tail) ->
@turboMaCk
turboMaCk / bookmarklet.js
Created May 23, 2020 11:07
Damejidlo.cz - retry order
javascript:(function(){function tryOrder(){window.setTimeout(function(){var btn=document.getElementsByClassName('Button Button--cartContainer')[0],evnt=document.createEvent('Events');evnt.initEvent('click', true, false);btn.dispatchEvent(evnt);tryOrder();},3000)}})()
module ContextView exposing (ContextItem, container, item)
import Html exposing (Html, Attribute)
import Html.Attributes as Attrs
type ContextItem = ContextItem
container : List (Attribute msg) -> (ContextItem -> List (Html msg)) -> Html msg
container attrs inner =
Html.div (Attrs.class "some-required-context-thing" :: attrs) <|
@turboMaCk
turboMaCk / Main.elm
Last active April 15, 2020 10:20
Elm tail call optimization
module Main exposing (main)
import Html
sumFromZero : Int -> Int
sumFromZero n =
sumFromZeroTail 0 n
sumFromZeroTail : Int -> Int -> Int
sumFromZeroTail acc n =
@turboMaCk
turboMaCk / main.rs
Last active November 30, 2017 11:58
Simple rust program which deals with file reads in 3 different ways
// This program will read test.txt file and print it line by line
// implemented in 3 different ways
use std::io::BufReader;
use std::io::BufRead;
use std::fs::File;
fn main() {
// Procedural
Verifying that "turbo_mack.id" is my Blockstack ID. https://onename.com/turbo_mack
@turboMaCk
turboMaCk / brew_reinstall_all.sh
Last active February 14, 2017 17:44
Reinstall all home brew packages
#!/bin/bash
# Reinstall all brew packages and dependencies in the correct order
# - list all installed packages
# - print the package followed by its dependencies
# - print the package and a single depenency on each line
# - perform a topographical sort
# - print out each package in the correct order on a single line
# - pass to brew reinstall
brew list \
@turboMaCk
turboMaCk / currying.js
Last active November 16, 2016 00:22
Currying vs partial application vs factory
/**
Example is using Heron's formula for calculating area of triangle
more info: https://en.wikipedia.org/wiki/Heron%27s_formula
*/
// Given a function of type f: (X x Y x Z) -> N,
// currying produces f: X -> (Y -> (Z -> N))
// Num -> (Num -> (Num -> Num))
@turboMaCk
turboMaCk / func.erl
Last active October 13, 2016 11:36
Erlang recursion examples
-module(func).
-export([fac/1, ft/1, len/1, lt/1, fib/1, tail_fib/1]).
%% basic recursive implementation of factorial
fac(N) when N == 0 -> 1;
fac(N) when N > 0 ->
N*fac(N-1).
%% Tail recursion implementation of factorial
@turboMaCk
turboMaCk / func.erl
Created October 13, 2016 11:29
Erlang recursion examples
-module(func).
-export([fac/1, ft/1, len/1, lt/1, fib/1, tail_fib/1]).
%% basic recursive implementation of factorial
fac(N) when N == 0 -> 1;
fac(N) when N > 0 ->
N*fac(N-1).
%% Tal recursion implementation