Skip to content

Instantly share code, notes, and snippets.

View mverzilli's full-sized avatar

Martin Verzilli mverzilli

View GitHub Profile
import Html (..)
import Html.Attributes (..)
import Html.Events (..)
import Signal
import Graphics.Collage (collage, filled, rect, toForm, move, rotate)
import Graphics.Element (Element, image)
import Window
import Color (..)
import Keyboard (arrows)
import Text (asText)
package simurrythmia.ui.util;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
### Keybase proof
I hereby claim:
* I am mverzilli on github.
* I am mverzilli (https://keybase.io/mverzilli) on keybase.
* I have a public key whose fingerprint is 1A62 F4E8 C9E1 3F5E 913E 60A4 029B 117E D8E9 4948
To claim this, I am signing this object:
@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]
@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 / 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 / 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 / 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 / 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 / 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.