Instantly share code, notes, and snippets.

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 {
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] }
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
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 = '.'
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
View look_ahead_lookup_table.rb
require 'pp'
class RuleOption
attr_accessor :parts
def initialize(*parts)
@parts = parts
end
end
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
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
View rubik.rb
require 'pp'
class Cube
attr_accessor :cells
def initialize
@cells = {
top: [0] * 9,
front: [1] * 9,
left: [2] * 9,