Skip to content

Instantly share code, notes, and snippets.

View itarato's full-sized avatar

Peter Arato itarato

  • Montreal, Canada
  • 12:10 (UTC -03:00)
View GitHub Profile
@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
@itarato
itarato / rubik.rb
Last active December 26, 2017 00:59
Rubik cube algorithm seeker.
require 'pp'
class Cube
attr_accessor :cells
def initialize
@cells = {
top: [0] * 9,
front: [1] * 9,
left: [2] * 9,
@itarato
itarato / add_frozen_heading.rb
Last active December 13, 2017 01:18
Adds frozen headers to all ruby files in a folder.
# Call: ruby add_frozen_heading.rb PATH_TO_FOLDER
dir = ARGV[0] || ''
if !Dir.exist?(dir)
puts 'Missing folder.'
exit
end
def check_headers(dir)
# puts "Inspect #{dir}"
@itarato
itarato / ruby_prof_diff.rb
Last active December 9, 2017 20:34
RubyProf diff printer
require 'pp'
require 'ostruct'
require 'cgi'
class CallChild
attr_accessor(
:file,
:method,
:callee_called,
:callee_line,
@itarato
itarato / diff_inverter.cpp
Created September 14, 2017 14:14
Diff inverter
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char* argv[]) {
ifstream file(argv[1]);
string s;