Skip to content

Instantly share code, notes, and snippets.

@yhirose
yhirose / immutable_update.js
Last active Jul 5, 2021
Immutable object update
View immutable_update.js
// 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;
View gist:466445794e3fc6dafa5d6534a8b3226d
#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_);
}
View gist:49b521ac887c7a0bd63f61130d93316e
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
ArrayInt Translator examples with ANTLR 4 and cpp-peglib
View ArrayInt.cpp
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include "peglib.h"
using namespace peg;
using namespace std;
bool translate(const string& text, string& result) {
View gist:fb390a892d84423d79799c6b6bf51f97
[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
View yhirose-karabiner-elements-complex-modifications.json
{
"title": "For yhirose's HHKB",
"rules": [
{
"description": "Change Shift+Esc to ~",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "escape",
View calc.peg
Expr ← Sum
Sum ← Product (('+' / '-') Product)*
Product ← Value (('*' / '/') Value)*
Value ← [0-9]+ / '(' Expr ')'
View debug.h
#define debug(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
// bash> tail -f debug.log
// bash> [command] 2> debug.log
@yhirose
yhirose / compress.go
Last active Feb 4, 2016 — forked from svett/compress.go
ZIP archives in Golang
View compress.go
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
)
func zipit(source, target string, needBaseDir bool) error {
zipfile, err := os.Create(target)
View stacktrace.go
i := 0
for {
pc, fn, line, ok := runtime.Caller(i)
if ok == false {
break
}
fmt.Printf("[stack-%d] %s[%s:%d]\n", i, runtime.FuncForPC(pc).Name(), fn, line)
i++
}