Skip to content

Instantly share code, notes, and snippets.

@ymakino
ymakino / lazy.sml
Last active November 1, 2019 05:44
SML exercise of an infinite list implementation.
signature LAZY =
sig
type 'a lazy
val lazy : (unit -> 'a) -> 'a lazy
val immediate : 'a -> 'a lazy
val force : 'a lazy -> 'a
end
structure Lazy :> LAZY =
struct
@ymakino
ymakino / helper.sml
Last active November 12, 2019 00:24
Helper functions for daily use in SML.
signature HELPER =
sig
val power : int * int -> int
val apply : ('a -> 'b) * 'a -> 'b
val id : 'a -> 'a
val curry : ('a * 'b -> 'c) -> ('a -> 'b -> 'c)
val uncurry : ('a -> 'b -> 'c) -> ('a * 'b -> 'c)
val flip : ('a * 'b -> 'c) -> ('b * 'a -> 'c)
val toBin : int -> string
val toOct : int -> string
@ymakino
ymakino / simple_stop_watch.rb
Created May 27, 2012 12:26
A simple ruby program for measuring time duration.
#!/usr/bin/env ruby
class SimpleStopWatch
def initialize()
@base = Time.now
@pausing = false
@pausing_secs = 0
@min = 0
@sec = 0
@rem = 0
@ymakino
ymakino / y2t.rb
Created May 27, 2012 12:39
A simple Ruby program to convert horizontal text to vertical text.
#!/usr/bin/env ruby -Ku -w
def resize(a, blank, s)
num = s - a.size
return a if num==0
if num > 0
num.times { a.push(blank) }
else
@ymakino
ymakino / router.pml
Created January 14, 2013 04:03
A rough routing protocol implementation based on Distributed Bellman-Ford algorithm in Promela.
#define NODES 5
#define LINKS 25
#define INVALID 255
#define INFINITY 16
#define _(from, to) ((from) * NODES + (to))
mtype = {msg};
@ymakino
ymakino / sudoku.mod
Last active December 11, 2015 13:18
A simple sudoku solver for GLPK.
#
# Usage: glpsol -m sudoku.mod -o sudoku.sol
#
set Number := 1..9;
set GNumber := 0..2;
set Group{i in GNumber} := i*3+1..i*3+3;
var cell{Number, Number, 0..9} binary;
var answer_cell{Number, Number} integer;
package emergencybutton;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <linux/i2c-dev.h>
#define I2C_FILE "/dev/i2c-1"
#define BMP180_I2C_ADDR 0x77
#!/usr/bin/env -S jruby -I .
require 'echowand.jar'
java_import 'echowand.service.Core'
java_import 'echowand.service.Service'
java_import 'echowand.net.InetNodeInfo'
java_import 'echowand.common.EOJ'
java_import 'echowand.common.EPC'
@ymakino
ymakino / dining_philosophers_problem.go
Last active May 11, 2023 10:16
An implementation of the dining philosophers problem in Go.
package main
import (
"fmt"
"time"
"math/rand"
)
var msg = &struct{}{}