Skip to content

Instantly share code, notes, and snippets.

@mverzilli
mverzilli / TimelockController.json
Created August 23, 2021 19:00
TimelockController ABI
[
{
"inputs": [
{
"internalType": "uint256",
"name": "minDelay",
"type": "uint256"
},
{
"internalType": "address[]",
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArlNte/eRXh5rFRFbKzqIb15Vir2gyyLCu1Lfq5oLGCNS4XFTN9zZTJLFg+g3iY4K5x7omKK/+D+fRvcHRT0T8/pt2zfHpmNV7qZDkwiJSBEyO2o/51/BM/4Pfd03jrYlt3MTwYL8s0BqFAztRJEhg3oqIbFZDYRTCjGelwQ4NCbGAjQPuXkZIF60LuyorH02BjNBwaWAJxcK9FDz9rF8aXM7L59AoZZNDpPJp8HjX6LtwrQvQoSQ7RcwrTCa6RR6JOPh8KraqhYkZLwa2Wo2AU3YESo+RdzMaUaEFy98NeVTpQbGI5lXVdrFjPj5RyT9iyLsm/zNn7nKpLFPL58eFQ== mverzilli@mscebba.manas.com.ar
@mverzilli
mverzilli / interf.cr
Last active July 19, 2017 14:05
Using modules as interfaces in Crystal
module Foo
abstract def foo_sth
end
class SomeFoo
include Foo
end
class Bar
def initialize(@foo : Foo)
@mverzilli
mverzilli / how_we_build_crystal_the_executable.md
Last active April 9, 2017 15:34
How we build `crystal`, the executable

How we build crystal, the executable

Note: most of this article is simply an incomplete natural language narration of what Crystal's Makefile specifies. If you, like me, feel a bit intimidated by Make, you may find this article more welcoming than venturing into the code by yourself and figuring things out from scratch.

At the root level of crystal-lang/crystal there's a Makefile that triggers the build process. The default task in that Makefile is crystal. That task checks whether there's a .build/crystal executable. To build the executable, you first need its dependencies (DEPS) and the source code (SOURCES).

With the dependencies built and the list of source code files, we are ready to compile Crystal, by running a previous version of the compiler that sits at bin/crystal. The new compiler will be written to .build/crystal.

@mverzilli
mverzilli / gist:3112e642f5c2f9eb2d171cfeb75f09e3
Created January 9, 2017 15:33
Crystal case in types vs. values
def get()
if 2 > 1
{"String", {"foo" => "bar"}}
else
nil
end
end
x = get
case x; when {String, Hash}; p typeof(x); end
@mverzilli
mverzilli / piedoom.cr
Last active September 16, 2016 00:55
piedoom's problem
require "json"
class Blog
JSON.mapping({
name: {type: String},
likes: {type: Int32},
following: {type: Int32},
default_post_format: {type: String},
})
end
@mverzilli
mverzilli / circle.yml
Created June 15, 2016 14:35
CircleCI for Crystal Projects
# Include this file in your project's root folder to integrate with CircleCI.
# Replace 0.18.0 with the Crystal version you're using.
dependencies:
cache_directories:
- "crystal-0.18.0-1"
pre:
- if [[ ! -e crystal-0.18.0-1 ]]; then wget https://github.com/crystal-lang/crystal/releases/download/0.18.0/crystal-0.18.0-1-linux-x86_64.tar.gz && tar xvfz crystal-0.18.0-1-linux-x86_64.tar.gz; fi
test:
pre:
- crystal-0.18.0-1/bin/crystal deps
@mverzilli
mverzilli / kmanas.cr
Created March 7, 2016 18:02
Crystal implementation of Kmeans for a poll @ Manas,
require "csv"
MINIMUM_DISTANCE = 0.85
SIMILARITY_LOW_BOUND = 0.30
SIMILARITY_HIGH_BOUND = 0.60
BIT_DICTIONARY = ["1a", "1b", "1c", "1d", "2a", "2b", "2c", "2d", "3a", "3b", "4a", "4b", "4c", "5a", "5b", "5c", "5d", "6a", "6b", "6c", "7a", "7b", "7c", "8a", "8b", "8c", "9a", "9b", "9c", "9d", "9e", "9f", "9g", "10a", "10b", "10c", "10d", "11a", "11b", "12a", "12b", "12c", "13a", "13b", "13c", "13d"]
RANDOM = Random.new 23
@mverzilli
mverzilli / pseudo_hash
Created December 15, 2015 13:46
Simulando acceso indexado en CodeGames :)
function states(i)
if i == 0
state0
else
if i == 1
state1
else
if i == 2
state2
else
@mverzilli
mverzilli / inverse_matrix.cr
Created October 18, 2015 21:28
Invert a matrix with Crystal via Lapack bindings
@[Link(framework: "Accelerate")]
lib LibLapack
fun sgetrf_(m: Int32*, n: Int32*, a: Void*, lda: Int32*, ipiv: Int32*, info: Int32*)
fun sgetri_(n: Int32*, a: Void*, lda: Int32*, ipiv: Int32*, work: Void*, lwork: Int32*, info: Int32*)
end
# Matrix A (the one being inverted)
# Matrix [1 2
# 3 4]