Skip to content

Instantly share code, notes, and snippets.

@ymakino
ymakino / ipv4_validator.py
Last active June 21, 2023 03:02
An IPv4 address validator in Python. An example of an implementation of a regular expression.
#!/usr/bin/env python3
# Regular Expression:
# (0|1[0-9]{0,2}|[2-9][0-9]?|2[0-4]?[0-9]|25[0-5])
# .(0|1[0-9]{0,2}|[2-9][0-9]?|2[0-4]?[0-9]|25[0-5])
# .(0|1[0-9]{0,2}|[2-9][0-9]?|2[0-4]?[0-9]|25[0-5])
# .(0|1[0-9]{0,2}|[2-9][0-9]?|2[0-4]?[0-9]|25[0-5])
import sys
@ymakino
ymakino / reversi.js
Last active June 1, 2023 05:17
An implementation of Reversi written in JavaScript.
#!/usr/bin/env node
function println() {
print(...arguments);
process.stdout.write("\n");
}
function print() {
for (d of arguments) {
process.stdout.write(d.toString());
@ymakino
ymakino / scheduler.js
Last active September 1, 2023 07:02
A sample implementation of a task scheduler with channel events in JS.
const MAX_PRIORITY = 10;
const MAX_CHANNELS = 1000;
const MAX_EVENTS = 1000;
let task_queues = [];
let event_queue = [];
let event_waiting_tasks = [];
let channels = [];
let step_delay=50;
@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{}{}
#!/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'
#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
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;
@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;
@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 / 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