Skip to content

Instantly share code, notes, and snippets.

View itarato's full-sized avatar

Peter Arato itarato

  • Montreal, Canada
View GitHub Profile
@itarato
itarato / dmg_beep.rs
Created April 30, 2019 01:08
DMG Boot logo beep sound prototype.
extern crate sdl2;
use sdl2::audio::{AudioCallback, AudioSpecDesired};
use std::sync::{Arc, Mutex};
use std::time::Duration;
struct SoundPacket {
pitch: f32,
len: Option<usize>,
volume: f32,
@itarato
itarato / serde_json_dig.rs
Created December 8, 2018 13:49
Serde JSON nest digger
use serde_json::Value;
#[derive(Debug)]
enum Shovel {
Key(&'static str),
Index(usize),
}
fn dig(val: Value, with: &[Shovel]) -> Option<Value> {
if with.len() == 0 {
@itarato
itarato / translation.rb
Last active November 28, 2018 14:13
Translation finder
# USAGE: ruby PATH_TO_SCRIPT/translation.rb "TOKEN_TO_TRANSLATE"
require 'yaml'
LANG = 'en'
subject = ARGV[0].split('.')
`find . -name '#{LANG}.yml'`
.lines
.map { |line| YAML.load(IO.read(line.strip))[LANG] }
@itarato
itarato / nqueen.rb
Last active November 9, 2018 01:03
N-Queen with recursive and non-recursive algorithm
require 'pp'
def run_test
make_board = -> { 8.times.map { [0] * 8 } }
board = make_board.call
return false unless ok?(board)
board = make_board.call
board[0][0] = 1
@itarato
itarato / stacklang.cpp
Created October 27, 2018 20:29
Stack base interpreter
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <regex>
#include <unordered_map>
#include <cmath>
using namespace std;
using value_t = double;
@itarato
itarato / brainfuck_interpreter.hs
Created May 27, 2018 12:26
Brainfuck interpreter.
import Data.Char
data VM = VM {
mem :: [Int],
ptr :: Int
}
tPlus = '+'
tMinus = '-'
tDot = '.'
@itarato
itarato / discount_code_creation.go
Last active May 11, 2018 13:21
Stress test of discount code creation
package main
import "gopkg.in/resty.v1"
import "fmt"
import "log"
import "strconv"
import "sync"
func main() {
var wg sync.WaitGroup
@itarato
itarato / look_ahead_lookup_table.rb
Last active May 3, 2018 01:19
Look-ahead table generator from non-empty deterministic grammar.
require 'pp'
class RuleOption
attr_accessor :parts
def initialize(*parts)
@parts = parts
end
end
@itarato
itarato / parse_json.hs
Last active January 4, 2018 23:49
Functional JSON encoder / decoder.
-- Custom data types
data Value = ValueString String | ValueInt Int | ValueJson Json deriving (Show)
data KeyValuePair = KeyValuePair String Value deriving (Show)
data Json = JsonObject [KeyValuePair] | JsonArray [Value] deriving (Show)
-- Decoder
decode :: String -> Value
decode raw = v
@itarato
itarato / match_search.rb
Last active December 22, 2017 18:39
Match making model - solution goes into `generate_new_meeting`.
## CONSTS #####################################################################
PERSON_NUM = 32
# Number of meeting iterations.
ITERATION = 64
## METHODS ####################################################################
# Generates start-state meetings with the number of iterations
def generate_old_meetings