Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Wonicon / recover_timestamp.fish
Created December 20, 2019 09:51
Recover timestamp for images taken out from Google photos
function change_ts
set json $argv[1]
set img $argv[2]
set ts_epoch (jq '.photoTakenTime.timestamp' $json | grep --only-matching "[0-9]\+")
set title (jq '.title' $json | sed 's/^"\(.*\)"$/\1/')
set ts_fmt (date --utc --date=@$ts_epoch)
cp $img "../out/$title"
touch --date="$ts_fmt" "../out/$title"
end
@Wonicon
Wonicon / convert.rb
Created July 7, 2018 14:20
Convert Katakana to Sogou Phrases
require 'romaji'
kana = {}
File.readlines('ciel').each do |line|
m = line.match(/([\p{Hiragana}\p{Katakana}ー]+)/)
kana[m[0]] = 1 if m
end
kana.keys.sort.each do |k|
@Wonicon
Wonicon / stick-1.c
Created March 8, 2018 06:58
Move sticks to keep equations true
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *digits[] =
{
"1110111",
"0100100",
"1011101",
@Wonicon
Wonicon / Chapter_5.md
Created November 2, 2017 17:49
Art of Multiprocessor Notes

CH.5

关注同步(synchronization)所需要的设施。

5.1

consensus: an elementary synchronization problem

consensus object: decide(), called at most once

@Wonicon
Wonicon / Pattern.txt
Created October 4, 2017 17:45
My Table Definition for Exposed
object <table-plural> : ... {
val <column> = ...
val <column> = reference(..., <another-table>)
...
}
=>
class User(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<User>(Users)
@Wonicon
Wonicon / index.php
Created September 23, 2017 07:27
Masonry Demo
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" >
<script src="masonry.pkgd.js"></script>
</head>
<body>
<div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 250 }'>
<?
$dir = scandir('Phone');
$dir = array_filter($dir, function($item) {
@Wonicon
Wonicon / setup.sh
Created April 21, 2017 15:33
Setup
apt install git
git clone https://github.com/Wonicon/dotfile.git .dotfile
ln -s .dotfile/vim/vimrc .vimrc
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
apt install -y fish ruby build-essential
apt install -y ruby-dev zlib1g-dev libxml2-dev
@Wonicon
Wonicon / gen_mk.rb
Created April 5, 2017 10:05
gem5 benchmarks cocurrent control
#!/usr/bin/env ruby
# Uage: <script> <runscripts> <makefile>
runscripts = File.read(ARGV[0])
makefile = File.open(ARGV[1], 'w')
configs = runscripts.each_line.map{ |line| line.split(' ')[4].split('/')[-1] }
makefile.puts("task := #{configs.map{ |c| "finish.#{c}" }.join(' ')}")
makefile.puts
@Wonicon
Wonicon / AntrlExt.java
Created March 28, 2017 10:31
Check ancestor in ANTLR
import org.antlr.v4.runtime.ParserRuleContext;
public class AntlrExt {
public static boolean underContext(ParserRuleContext curr, ParserRuleContext target, ParserRuleContext limit) {
do {
curr = curr.getParent();
} while (curr.getRuleIndex() != target.getRuleIndex() && curr.getRuleIndex() != limit.getRuleIndex());
return curr.getRuleIndex() == target.getRuleIndex();
}
}
@Wonicon
Wonicon / GrayCodeIndex.scala
Created March 5, 2017 13:26
GrayCounter found in rocket-chip repo, and verify their index generation logic (why double the gray code space and then calc them down?)
import chisel3._
import chisel3.util._
import chisel3.iotesters._
object GrayCounter {
def apply(bits: Int, inc: Bool = Bool(true), clear: Bool = Bool(false)): UInt = {
// Incremented
val next = Wire(UInt(width = bits))
val curr = Reg(next = next)
next := Mux(clear, UInt(0), curr + inc.asUInt)