Skip to content

Instantly share code, notes, and snippets.

View guilleiguaran's full-sized avatar
💭

Guillermo Iguaran guilleiguaran

💭
View GitHub Profile
@guilleiguaran
guilleiguaran / monoids.rb
Created February 22, 2019 20:25 — forked from KamilLelonek/monoids.rb
Monoids examples in Ruby
[1] (pry) main: 0> 1.class
=> Fixnum
[2] (pry) main: 0> 1.method(:+)
=> #<Method: Fixnum#+>
[3] (pry) main: 0> 1 + 0 == 0 + 1
=> true
[4] (pry) main: 0> 2.0.class
=> Float
[5] (pry) main: 0> 2.0.method(:*)
@guilleiguaran
guilleiguaran / custom_monoid.rb
Created February 22, 2019 20:25 — forked from KamilLelonek/custom_monoid.rb
An example of class monoid in Ruby
[1] (pry) main: 0> class AdditionMonoid
[1] (pry) main: 0* def identity
[1] (pry) main: 0* 0
[1] (pry) main: 0* end
[1] (pry) main: 0*
[1] (pry) main: 0* def operation(a, b)
[1] (pry) main: 0* a + b
[1] (pry) main: 0* end
[1] (pry) main: 0* end
=> :operation
@guilleiguaran
guilleiguaran / governmentify.sh
Created May 12, 2018 17:28 — forked from krusynth/governmentify.sh
Uses ImageMagick to read in a text file, transform it into an image, rotate it, add noise, and output as a pdf.
cat ./1-219.1.txt | convert \
-font Courier \
text:- \
-rotate `convert null: -format '%[fx:rand()*15-7]' info:` \
-attenuate 0.1247 +noise Gaussian \
-colorspace Gray \
1-219.1.pdf
@guilleiguaran
guilleiguaran / percona-toolkit.rb
Created October 19, 2017 17:45
Homebrew Formula for Percona Toolkit 2.2.19
class PerconaToolkit < Formula
desc "Percona Toolkit for MySQL"
homepage "https://www.percona.com/software/percona-toolkit/"
url "https://www.percona.com/downloads/percona-toolkit/2.2.19/tarball/percona-toolkit-2.2.19.tar.gz"
mirror "https://www.mirrorservice.org/sites/ftp.netbsd.org/pub/pkgsrc/distfiles/percona-toolkit-2.2.19.tar.gz"
mirror "https://dl.bintray.com/homebrew/mirror/percona-toolkit-2.2.19.tar.gz"
sha256 "e9f4d4730265813fa7a39ed8799d12ca5775c8e5d6fa27ff48bae11db0f7e671"
revision 1
head "lp:percona-toolkit", :using => :bzr
import Kitura
import KituraNet
import KituraSys
let router = Router()
router.get("/") {
request, response, next in
response.send("Hello, World!")
next()
defmodule MyMod do
defmodule Base do
def __using__(_) do
end
end
@mod Application.get_env(:my_app, :mod, MyMod.Base)
use @mod
end
defmodule Contracts do
defmacro __using__(_opts) do
quote do
Module.register_attribute(__MODULE__, :requires, accumulate: true)
Module.register_attribute(__MODULE__, :ensures, accumulate: true)
@contracts %{}
import Kernel, except: [def: 2]
import Contracts, only: [def: 2]
% MIX_ENV=stag mix release
==> Building release with MIX_ENV=stag.
==> Generating relx configuration...
==> Merging custom relx configuration from rel/relx.config...
==> Generating sys.config...
==> Generating boot script...
==> Performing protocol consolidation...
==> Conform: Loading schema...
==> Conform: No schema found, conform will not be packaged in this release!
==> Generating release...

Make illegal states unrepresentable. Use the type system as a tool to enforce invariants on the code you write. Choose your data types such that states that are illegal don’t show up as legal states in the program. Take this code representing various connection information as an example. It keeps track of relevant information in a fairly readable manner:

type connection_state =
  | Connecting
  | Connected
  | Disconnected

type connection_info = {
 state: connection_state