Skip to content

Instantly share code, notes, and snippets.

@sekia
sekia / dotenv.sh
Last active October 1, 2021 09:32
dotenv version of env(1)
#!/bin/zsh
set -e
file=$(pwd)/.env
if [[ ! -e $file ]]; then
echo File not found: $file > /dev/stderr
exit 1
fi
@sekia
sekia / show-total-price-of-amazon-jp-auto-delivery.user.js
Last active May 3, 2024 08:48
Greasemonkey User Script: Shows total price of incoming auto delivery on Amazon.co.jp
// ==UserScript==
// @name Show total price of incoming auto delivery on Amazon.co.jp
// @version 1
// @grant none
// @match https://www.amazon.co.jp/auto-deliveries*
// @exclude /^https:\/\/www\.amazon\.co\.jp\/auto-deliveries\/[^?]/
// ==/UserScript==
/**
* Each .subscription-price-container element has price of corresponding item in JPY and (optinally) purchasing quantity.
@sekia
sekia / placement.cc
Created May 7, 2021 12:33
Slab allocator using C++ 20 <bit> library
#include <array>
#include <bitset>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <new>
#include <utility>
#include <vector>
@sekia
sekia / content.html
Created March 19, 2020 08:09
Example of communication with same-origin iframe using |window.postMessage|.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>IFrame Content</title>
</head>
<body>
<form id="ui-container">
<input id="ui" />
<button type="submit">Apply Changes</button>
@sekia
sekia / data.js
Created March 10, 2020 10:43
Flow's predicate functions' quirk (checked on flow-bin v0.120.1)
// @flow
export type A = 'A';
export type B = 'B';
export type T = A | B;
export function isA(data: T): %checks {
return data === 'A';
@sekia
sekia / classify_zh_sentence.pl
Created September 11, 2018 19:24
Example classification program for Chinese text, using Algorithm::LibLinear.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature qw/say state/;
use Algorithm::LibLinear;
use Lingua::ZH::Jieba; # Word segmentor for Chinese language.
use Text::Ngrams; # Language-independent n-gram generator.
@sekia
sekia / pun.pl
Created March 23, 2018 16:13
Punnig operator for scalars.
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw/say/;
use PadWalker qw/var_name/;
my $foo = 42;
my $bar = 'blah blah blah';
my $baz = undef;
@sekia
sekia / actor.ml
Created July 26, 2017 09:40
Since js_of_ocaml cannot transform tail call of function given as an argument into simple loop, event loop with Lwt.bind (>>=) is unimplementable.
let () =
let n = int_of_string Sys.argv.(1) in
let open Lwt.Infix in
let ping = Lwt_mvar.create_empty () in
let rec consumer () =
Lwt_mvar.take ping >>= function
| false -> Lwt.return_unit
| true -> print_endline "ping"; consumer () in
let producer () =
let rec loop i = Lwt_mvar.put ping (i < n) >>= fun () -> loop (i + 1) in
@sekia
sekia / mnist.cc
Last active July 26, 2017 10:15
MNIST baseline classifier using kNN method.
#include <algorithm>
#include <arpa/inet.h>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <istream>
#include <numeric>
#include <set>
#include <stdexcept>
#include <string>
@sekia
sekia / float_cmp.cc
Created February 21, 2017 11:38
Exploit IEEE 754 spec's property on comparing non-zero numbers.
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <limits>
using namespace std;
template <size_t Bits>
struct IntegerTrait {};