Skip to content

Instantly share code, notes, and snippets.

View akr4's full-sized avatar

UEDA Akira akr4

  • Tokyo, Japan
View GitHub Profile
@akr4
akr4 / multiple_writes.rs
Last active September 14, 2022 08:24
SQLite "database is locked" reproducer
//! A reproducer of the 'database is locked' error.
//! https://www2.sqlite.org/cvstrac/wiki?p=DatabaseIsLocked
//!
//! The error happens like this:
//! ```
//! thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Database(SqliteError { code: 5, message: "database is locked" })', src/bin/multiple.rs:35:22
//! ```
//! The code is "5", while the wiki page says it is 6.
//!
//! ```toml
@akr4
akr4 / gist:f8ccd4e7a475e99d30772ffb9ee1a078
Last active August 19, 2022 05:15
SQLite 複数接続使用時の挙動テスト
use sqlx::sqlite::SqlitePoolOptions;
use anyhow::Result;
use sqlx::{Row, SqlitePool};
fn main() {}
#[tokio::test]
async fn test() -> Result<()> {
const LOOP_COUNT: usize = 10;
let db_dir = tempfile::tempdir()?;
@akr4
akr4 / tree.rs
Last active September 22, 2019 23:10
tree! macro which generates tree on leetcode
use std::cell::RefCell;
#[cfg(test)]
use std::collections::LinkedList;
use std::rc::Rc;
#[derive(Debug, PartialEq, Eq)]
pub struct TreeNode {
pub val: i32,
pub left: Option<Rc<RefCell<TreeNode>>>,
pub right: Option<Rc<RefCell<TreeNode>>>,
@akr4
akr4 / list_node.rs
Last active September 15, 2019 02:52
list! macro for ListNode on leetcode
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>,
}
impl ListNode {
#[inline]
fn new(val: i32) -> Self {
ListNode { next: None, val }

Keybase proof

I hereby claim:

  • I am akr4 on github.
  • I am akr4 (https://keybase.io/akr4) on keybase.
  • I have a public key ASDy2rbkgMGELpnY2TMrZiXjH5F5N1ezWt1HMB2K-0f-igo

To claim this, I am signing this object:

@akr4
akr4 / gist:3782cba821d7711c724062d3da0df599
Created April 20, 2019 04:38
list all paths from a json
# https://github.com/stedolan/jq/issues/243#issuecomment-48470943
jqpath () {
jq '[path(..)|map(if type=="number" then "[]" else tostring end)|join(".")|split(".[]")|join("[]")]|unique|map("."+.)|.[]'
}
String a = "𠮷";
System.out.println("original: " + a);
System.out.println("length: " + a.length());
System.out.println("decoded: " + a.codePoints().mapToObj(Character::toChars).map(String::valueOf).collect(Collectors.joining(",")));
@akr4
akr4 / 1.py
Last active September 28, 2016 02:18
Python's XMLPullParser runs out of memory
import xml.etree.ElementTree as ET
import argparse
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('in_file')
args = arg_parser.parse_args()
def main(args):
with open(args.in_file) as f:
parser = ET.XMLPullParser(['start', 'end'])
import numpy as np
import chainer
from chainer import cuda, Function, gradient_check, report, training, utils, Variable, Chain
from chainer import datasets, iterators, optimizers, serializers
from chainer import Link, Chain, ChainList
import chainer.functions as F
import chainer.links as L
from chainer.training import extensions
@akr4
akr4 / any2pdf
Last active March 10, 2022 06:18
convert any format supported by Pygments to pdf
#!/bin/sh
# Usage:
# ./any2pdf index.html
# ./any2pdf main.go
#
# Requirements:
# - Pygments
# - ImageMagick
# - wkhtmltopdf