Skip to content

Instantly share code, notes, and snippets.

@yhirose
yhirose / froggy.py
Created July 7, 2022 10:47
Froggy - Simple game on Terminal
#!/usr/bin/env python3
import curses
import datetime
import locale
import noise
ROWS = 16
COLS = 16
def get_rows_and_cols(scr):
@yhirose
yhirose / calc.peg
Created May 8, 2022 13:57
Learn LLVM 12 - Chapter 03 - calc PEG grammar
calc <- decl expr
decl <- ('with' ident (',' ident)* ':')?
expr <- term (term_op term)*
term <- factor (factor_op factor)*
factor <- ident / number / '(' expr ')'
term_op <- < [+-] >
factor_op <- < [*/] >
@yhirose
yhirose / immutable_update.js
Last active July 5, 2021 13:24
Immutable object update
// Based on 'Easy immutable objects in Javascript'
// https://spapas.github.io/2018/04/05/easy-immutable-objects/
const immutable_update = (obj, path, val) => {
if (!val) {
return path.reduce((obj, [path, val]) => immutable_update(obj, path, val), obj);
}
let parts = (typeof path === 'string' || path instanceof String) ? path.split('.') : path;
#include <rocksdb/db.h>
class RocksDB {
public:
~RocksDB() { delete db_; }
rocksdb::Status open(const rocksdb::Options& options, std::string_view path) {
assert(!db_);
return rocksdb::DB::Open(options, std::string(path), &db_);
}
function fzf-default() {
fzf --multi --ansi --select-1 --exit-0 --reverse --height '40%'
}
function fzf-cd() {
local DIR=$(fd --type d | fzf +m --ansi --select-1 --reverse)
if [ -n "$DIR" ]; then
cd $DIR
fi
}
@yhirose
yhirose / ArrayInt.cpp
Last active May 23, 2019 14:48
ArrayInt Translator examples with ANTLR 4 and cpp-peglib
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include "peglib.h"
using namespace peg;
using namespace std;
bool translate(const string& text, string& result) {
[alias]
co = checkout
st = status
br = branch
ci = commit
l = log --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%<(16,trunc)%an%Creset%C(yellow)%d%Creset %s'
lg = log --date=short --pretty='format:%C(yellow)%h %C(cyan)%ad %C(green)%<(16,trunc)%an%Creset%C(yellow)%d%Creset %s' --graph
@yhirose
yhirose / yhirose-karabiner-elements-complex-modifications.json
Created January 5, 2018 19:51
My Karabiner-Elements Complex-Modifications
{
"title": "For yhirose's HHKB",
"rules": [
{
"description": "Change Shift+Esc to ~",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "escape",
Expr ← Sum
Sum ← Product (('+' / '-') Product)*
Product ← Value (('*' / '/') Value)*
Value ← [0-9]+ / '(' Expr ')'
@yhirose
yhirose / debug.h
Created July 20, 2016 23:11
Debug Print
#define debug(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
// bash> tail -f debug.log
// bash> [command] 2> debug.log