Skip to content

Instantly share code, notes, and snippets.

scudelletti / JSONSumTypeHaskell.hs
Last active Mar 16, 2021
Encode/Decode Sum Types manually using Aeson (Haskell) - No Generic
View JSONSumTypeHaskell.hs
{-# LANGUAGE OverloadedStrings #-}
module Stuff where
import Data.Aeson
import Data.ByteString.Lazy.Char8 as BC
data FooBar = Foo | Bar deriving (Eq, Show)
instance ToJSON FooBar where
View 1_problem.hs
-- In a hypothetical scenario where:
-- * I have packs of beverages
-- * Each pack belongs to a Brand (Coke or Pepsi) and contains a Product
-- * Each product belongs to a Brand (Coke or Pepsi)
-- * A Coke pack filled with Coke cans is correct
-- * A Coke pack filled with Pepsi cans is incorrect
-- Is there a way that I can make the type system check that for me during compilation time?
-- I know I could have smart constructors that would build the correct pack with the correct content but I'd like to know if there are other and smarter -- ways of achieving it.
scudelletti / import_and_extend.exs
Created Oct 25, 2018
Delegates methods to "imported" module on Elixir
View import_and_extend.exs
defmodule Father do
def sing() do
IO.puts "Lalalalalala"
def song(a, b) do
IO.puts "Lelelelelele #{a} #{b}"
View pir.ino
int ledPin = 13;
int pirPin = 2;
int default_remaining = 30;
int remaining = 0;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
scudelletti /
Created Apr 13, 2018
Export Env Variables stored on /etc/environment
# Loan Env Variables
while read line; do
export $(echo $line | sed 's/"//g')
done < /etc/environment
scudelletti / numbers_in_lambda_calculus.lisp
Last active Dec 10, 2018
Numbers in Lambda Calculus - Following Destroy All Software approach
View numbers_in_lambda_calculus.lisp
;; Church Numbers
(setq zero (lambda (f) (lambda (x) x)))
(setq one (lambda (f) (lambda (x) (funcall f x))))
(setq two (lambda (f) (lambda (x) (funcall f (funcall f x)))))
;; Manual Calc
(funcall (funcall zero (lambda (x) (+ 1 x))) 0)
(funcall (funcall one (lambda (x) (+ 1 x))) 0)
(funcall (funcall two (lambda (x) (+ 1 x))) 0)
scudelletti / Dockerfile
Last active Jun 21, 2017
Run GUI Linux Apps through Docker with xQuartz on MacOS
View Dockerfile
# How to Use
# open -a XQuartz
# socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
# docker build . -t ds-xclock
# docker run -e DISPLAY=YOUR_LOCAL_IP_HERE:0 -it ds-xclock
# Useful Links:
scudelletti / class_definition_in_specs.rb
Created May 27, 2016
How to avoid global constant in the specs
View class_definition_in_specs.rb
require 'spec_helper'
describe "Wow Coins" do
let(:klasz_class) do do
attr_reader :title
def initialize(properties)
@title = properties[:title]
scudelletti / ssh_config
Last active Apr 22, 2016
Forward port on SSH
View ssh_config
Host *
User someuser
ForwardAgent yes
LocalForward localhost:43306 localhost:3306
LocalForward localhost:49200 localhost:9200
LocalForward localhost:49001 localhost:9001
scudelletti / lambda_calculus.rb
Last active Nov 22, 2016
If condition on lambda calculus
View lambda_calculus.rb
# Rules: A lamda always has 1 parameter, nothing more, nothing less
# Useful Content:
# Identity lambda
IDENTITY = ->x { x }
# True, returns the first argument
TT = ->x { ->y { x } }
# False, returns the last argument