Skip to content

Instantly share code, notes, and snippets.

Avatar
😐
Focusing

Peter Arato itarato

😐
Focusing
View GitHub Profile
@itarato
itarato / data_def.rb
Last active Nov 5, 2020
Playing with (almost) algebraic data definitions in Ruby
View data_def.rb
class Def
class DataContainer
def initialize(name)
@name = name
@members = []
@last_constructor = nil
Object.const_set(name, self)
end
@itarato
itarato / migrate_feature.rs
Last active Jun 14, 2020
Feature migration framework brainstorm
View migrate_feature.rs
use std::cell::{RefCell};
/****************************************
* Abstractions
*/
trait Task {
fn get_name(&self) -> String;
fn get_description(&self) -> String;
fn is_complete(&self) -> bool;
@itarato
itarato / game_of_life.c
Created Dec 6, 2019
Game of Life (in C/SDL)
View game_of_life.c
#include "SDL.h"
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#define SIZE 1000
struct cell {
@itarato
itarato / game_of_life.py
Created Dec 6, 2019
Game of Life (in Pyxel)
View game_of_life.py
import pyxel
import random
class App:
def __init__(self, size, game_of_life):
super().__init__()
self.size = size
self.game_of_life = game_of_life
@itarato
itarato / non_blocking_queue.c
Last active Sep 30, 2019
Non blocking queue.
View non_blocking_queue.c
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#define EXAMPLE_SIZE 100
#define CONSUMER_COUNT 10
static pthread_mutex_t q_mtx; // = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t q_cond = PTHREAD_COND_INITIALIZER;
@itarato
itarato / maze.hs
Last active Aug 19, 2019
Learning functional maze
View maze.hs
{-
Funcitonal Maze
Run: runhaskell <SOURCE> <WIDTH::Int> <HEIGHT::Int> <RANDOM_SEED::Int>
Control:
- [W] [A] [S] [D]: move up, left, down, right
- [Q] [E|SPACE]: rotate counter-clockwise, clockwise
- [ESC]: quit
-}
@itarato
itarato / parser_combinator.rb
Last active Feb 28, 2021
Parser combinator trial
View parser_combinator.rb
require 'pp'
require "test/unit"
class String
def parse_response
ParseResponse.new(self)
end
def token
for_tokens(self)
@itarato
itarato / dmg_beep.rs
Created Apr 30, 2019
DMG Boot logo beep sound prototype.
View dmg_beep.rs
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 Dec 8, 2018
Serde JSON nest digger
View serde_json_dig.rs
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 Nov 28, 2018
Translation finder
View translation.rb
# 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] }