Skip to content

Instantly share code, notes, and snippets.

😐
Focusing

Peter Arato itarato

View GitHub Profile
@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] }
@itarato
itarato / nqueen.rb
Last active Nov 9, 2018
N-Queen with recursive and non-recursive algorithm
View nqueen.rb
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 Oct 27, 2018
Stack base interpreter
View stacklang.cpp
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <regex>
#include <unordered_map>
#include <cmath>
using namespace std;
using value_t = double;
View brainfuck_interpreter.hs
import Data.Char
data VM = VM {
mem :: [Int],
ptr :: Int
}
tPlus = '+'
tMinus = '-'
tDot = '.'
@itarato
itarato / discount_code_creation.go
Last active May 11, 2018
Stress test of discount code creation
View discount_code_creation.go
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
Look-ahead table generator from non-empty deterministic grammar.
View look_ahead_lookup_table.rb
require 'pp'
class RuleOption
attr_accessor :parts
def initialize(*parts)
@parts = parts
end
end
@itarato
itarato / parse_json.hs
Last active Jan 4, 2018
Functional JSON encoder / decoder.
View parse_json.hs
-- 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 Dec 22, 2017
Match making model - solution goes into `generate_new_meeting`.
View match_search.rb
## CONSTS #####################################################################
PERSON_NUM = 32
# Number of meeting iterations.
ITERATION = 64
## METHODS ####################################################################
# Generates start-state meetings with the number of iterations
def generate_old_meetings
@itarato
itarato / rubik.rb
Last active Dec 26, 2017
Rubik cube algorithm seeker.
View rubik.rb
require 'pp'
class Cube
attr_accessor :cells
def initialize
@cells = {
top: [0] * 9,
front: [1] * 9,
left: [2] * 9,
You can’t perform that action at this time.