Skip to content

Instantly share code, notes, and snippets.

@LiosK
LiosK / fetch_quotes.pl
Created May 4, 2010 02:53
a simple perl script to fetch fund quotes from yahoo finance japan
#!/usr/bin/perl
# fetch fund quotes from yahoo finance japan
use utf8;
use strict;
use warnings;
use XML::LibXML;
use Finance::Quote;
# extract fund symbols from gnucash xml file
@LiosK
LiosK / extract_pricedb.pl
Created May 4, 2010 02:54
a code snippet to extract pricedb from gzipped gnucash xml file
#!/usr/bin/perl
# extract pricedb from gzipped gnucash xml file
use utf8;
use strict;
use warnings;
use XML::LibXML;
die 'specify gnucash xml file as argument' unless $ARGV[0];
my $doc = XML::LibXML->load_xml(location => $ARGV[0]);
@LiosK
LiosK / keepass2keeper.xsl
Created May 4, 2010 02:56
Convert KeePass XML (2.x) format to keeper.txt format.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- convert KeePass XML (2.x) format to 7-column keeper.txt format -->
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="/KeePassFile/Root/Group" />
</xsl:template>
@LiosK
LiosK / build.bat
Created December 27, 2010 14:14
runfor -- Runs a command for a given time, kills it after the time is out.
ghc -W -O -threaded --make runfor
@LiosK
LiosK / dcmvcf2ldif.pl
Created February 28, 2013 13:21
convert docomo vcard format to ldif
#!/usr/bin/perl
# convert docomo vcard format to ldif
use utf8;
use strict;
use warnings;
use Unicode::Normalize;
binmode(STDOUT, ':utf8');
die 'error: no vcard file specified (*.vcf)' if (@ARGV < 1);
@LiosK
LiosK / install_fq_in_mac.sh
Last active December 17, 2023 10:14
Install Perl modules in macOS system Perl without cluttering /usr/local
#!/bin/bash -x
# Install Perl modules in macOS system Perl without cluttering /usr/local
# Prerequisite
xcode-select --install
# Install modules locally, instructing cpanm to build Universal Binaries
sysperl=/usr/bin/perl
curl -L https://cpanmin.us/ | \
ARCHFLAGS='-arch arm64 -arch arm64e -arch x86_64' \
@LiosK
LiosK / join_transfer.py
Last active December 23, 2017 14:46
gncxml - join transfer account information if a transaction consists of only two splits
import gncxml
def join_transfer(sp):
pairs = sp.reset_index() \
.groupby(["trn_idtype", "trn_id"]) \
.filter(lambda x: len(x) == 2)
dup = pairs[["trn_idtype", "trn_id", "idtype", "id"]] \
.join(pairs.set_index(["trn_idtype", "trn_id"]) \
.add_prefix("transfer_"), \
on=["trn_idtype", "trn_id"])
from datetime import datetime
from secrets import randbits
from typing import Tuple
# In general, the layered approach demonstrates much better collision resistance than
# the naive approach when the per-second randomness field is sufficiently large to
# accommodate a possible number of concurrent generators. Otherwise, the layered
# approach tends to cause burst collisions when the per-second randomness collides.
LEN_PER_SEC = 16
LEN_PER_GEN = 4
@LiosK
LiosK / uuidv7.c
Last active November 17, 2023 13:05
Experimental stateless UUIDv7 implementation as of RFC draft 02
/**
* uuidv7.c - Experimental stateless UUIDv7 implementation as of RFC draft 02
*
* Required: `clock_gettime()`, `arc4random_buf()`, and ~15-microseconds or
* finer system clock resolution.
*
* This implementation employs 52-bit timestamp (consisting of 36-bit whole
* seconds and 16-bit sub-second fraction) and 70-bit cryptographically strong
* random integer in the following layout. It does not guarantee the monotonic
* order of the generated IDs within the same timestamp (i.e. within ~15
@LiosK
LiosK / base32.mjs
Last active March 8, 2022 04:07
Experimental base36 (modulo) and base32 (bitwise) binary-to-text encoders and decoders
const DIGITS = "0123456789abcdefghijklmnopqrstuv";
/** O(1) map from ASCII code points to digit values. */
const DECODE_MAP = new Uint8Array(128).fill(0xff);
for (let i = 0, uc = DIGITS.toUpperCase(); i < DIGITS.length; i++) {
DECODE_MAP[DIGITS.charCodeAt(i)] = i;
DECODE_MAP[uc.charCodeAt(i)] = i; // omit this to make decoder case-sensitive
}
/** Encodes a byte array to text. */