Skip to content

Instantly share code, notes, and snippets.

View FlorianCassayre's full-sized avatar

Florian Cassayre FlorianCassayre

View GitHub Profile
#include "LedControl.h"
#define SIZE 8
#define PIN_MATRIX_DATA 55
#define PIN_MATRIX_CLK 56
#define PIN_MATRIX_CS 54
#define PIN_BUTTON 57
@FlorianCassayre
FlorianCassayre / function.scala
Created April 25, 2018 17:17
Soit f(_) une fonction...
val f: Double => Double = x => x * x // Une fonction, peu importe
println(f(_)) // Il s'agit bien d'une fonction (anonyme)
val g: Double => Double = f(_) // On peut vérifier qu'elle typecheck
// On peut lui appliquer des valeurs normalement (ne pas oublier les parenthèses !)
println((f(_))(3)) // Affiche 9
@FlorianCassayre
FlorianCassayre / RayTracing.scala
Last active March 10, 2018 13:15
A basic ray tracer in Scala. "What I cannot create, I do not understand" (R. Feynman)
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
object RayTracing extends App {
private def sq(x: Double): Double = x * x
case class Point(x: Double, y: Double, z: Double) {
import scala.util.Random
import Fiddle.draw._
import org.scalajs.dom.{Event, EventTarget, MouseEvent}
import scala.collection.mutable.ArrayBuffer
val square = 50
val (width, height) = (Fiddle.canvas.width, Fiddle.canvas.height)
val (mapWidth, mapHeight) = (20 * square, 20 * square)
val (borderLeft, borderRight, borderTop, borderBottom) = (0, mapWidth, 0, mapHeight)
object CompteBonCombinations extends App {
val plates = {
val small = (1 to 10).toList
val big = List(25, 50, 75, 100)
small ++ small ++ big
}
val grouped = plates.groupBy(identity).mapValues(_.size)
@FlorianCassayre
FlorianCassayre / SelfDescription.java
Created September 10, 2017 20:42
Reproduction of "Self-Description" by xkcd (https://xkcd.com/688).
// Reproduction of "Self-Description" by xkcd (https://xkcd.com/688).
// @author Florian Cassayre
final int PANEL_WIDTH = 500, PANEL_HEIGHT = 400, PADDING = 50, WEIGHT = 4;
PFont font;
void setup()
{
surface.setSize(PANEL_WIDTH * 3 + PADDING * 2, PANEL_HEIGHT);
final int INITIAL_K = 0;
int k = INITIAL_K;
final int POINTS_PER_CLUSTER = 100;
final float POINTS_DEVIATION = 50;
final int INTERVAL = 100;
final ArrayList<Point> points = new ArrayList<Point>();
final ArrayList<Point> centroids = new ArrayList<Point>();
final HashMap<Point, Point> map = new HashMap<Point, Point>();
{"layers":[{"out_depth":1,"out_sx":24,"out_sy":24,"layer_type":"input"},{"sx":5,"sy":5,"stride":1,"in_depth":1,"out_depth":8,"out_sx":24,"out_sy":24,"layer_type":"conv","l1_decay_mul":0,"l2_decay_mul":1,"pad":2,"filters":[{"sx":5,"sy":5,"depth":1,"w":{"0":-0.002005437436999499,"1":0.11800762769429841,"2":0.15288575246122227,"3":0.17926717613376164,"4":-0.08993469726722844,"5":-0.20254829450417103,"6":0.15791114405597814,"7":0.31846451260019604,"8":0.01467962792660115,"9":-0.13848296305157726,"10":0.10341788356249301,"11":-0.06268045391638183,"12":0.6978074481239207,"13":-0.2938077242420065,"14":-0.5089319294176927,"15":-0.12264368305380181,"16":0.44763879656035277,"17":0.3359516007279942,"18":-0.06184286836783794,"19":-0.482255823490501,"20":0.3677897224446566,"21":0.10207491930585594,"22":0.21835092856908758,"23":-0.02092531346874951,"24":0.13842120306943864}},{"sx":5,"sy":5,"depth":1,"w":{"0":-0.43289539339825756,"1":-0.5130859925805419,"2":0.02528701695327489,"3":0.3359550133438127,"4":0.218543747256232,"5
final int HIDDEN_LAYERS = 1;
final int INPUTS = 4 * 2;
final int OUTPUTS = 4;
final int NEURONS_PER_LAYER = 16;
final float LEARNING_RATE = 0.1;
final float[][] neurons = new float[2 + HIDDEN_LAYERS][]; // [layer][neuron]
final float[][][] axons = new float[1 + HIDDEN_LAYERS][][]; // [layer][previous_neuron][next_neuron]
@FlorianCassayre
FlorianCassayre / BrainfuckInstruction.java
Last active June 3, 2017 19:42
A basic Brainf*** interpreter in java (with uncensored class names).
public enum BrainfuckInstruction
{
INCREMENT('+'),
DECREMENT('-'),
CURSOR_RIGHT('>'),
CURSOR_LEFT('<'),
LOOP_START('['),
LOOP_END(']'),
INPUT(','),
OUTPUT('.');