Skip to content

Instantly share code, notes, and snippets.

View tos-kamiya's full-sized avatar
:octocat:
one by one

Toshihiro Kamiya tos-kamiya

:octocat:
one by one
View GitHub Profile
@tos-kamiya
tos-kamiya / test_chdir_wo_fail.py
Created December 5, 2021 23:33
fix: os.chdir in unittest's test case causes a RecursionError on Windows 10
from typing import *
import os
import tempfile
import unittest
class ChdirTest(unittest.TestCase):
def test_chdir(self):
with tempfile.TemporaryDirectory() as tempdir:
@tos-kamiya
tos-kamiya / test_chdir_fails.py
Last active December 5, 2021 23:24
os.chdir in unittest's test case causes a RecursionError on Windows 10
import unittest
import os
import tempfile
class ChdirTest(unittest.TestCase):
def test_chdir(self):
with tempfile.TemporaryDirectory() as tempdir:
os.chdir(tempdir) # this results in remvoing the current directory, so causes an error on Windows
if __name__ == "__main__":
@tos-kamiya
tos-kamiya / nonblocking.py
Last active December 5, 2021 14:28
Non-blocking read from child process's stdout
# ref: https://stackoverflow.com/questions/375427/a-non-blocking-read-on-a-subprocess-pipe-in-python
# When I tried the answer in this article, I got the following warning and could not do it properly, so I fixed it.
# /usr/lib/python3.8/subprocess.py:842: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
from typing import *
import sys
from subprocess import PIPE, Popen
from threading import Thread
@tos-kamiya
tos-kamiya / Main.java
Last active October 26, 2021 23:53
Sieve of Eratosthenes in Java
import java.util.Arrays;
import java.util.stream.IntStream;
class Main {
public static int[] simpleSieve(int limit) {
boolean[] isPrime = new boolean[limit + 1];
Arrays.fill(isPrime, true);
for (int n = 2; n <= limit; n++) {
if (isPrime[n]) {
@tos-kamiya
tos-kamiya / sieve.py
Last active October 26, 2021 23:50
Sieve of Eratosthenes in Python
def simple_sieve(limit):
is_prime = [True] * (limit + 1)
for n in range(2, limit + 1):
if is_prime[n]:
for m in range(n * n, limit + 1, n):
is_prime[m] = False
return [n for n in range(2, limit + 1) if is_prime[n]]
@tos-kamiya
tos-kamiya / sieve.c
Last active November 2, 2021 04:39
Sieve of Eratosthenes in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int *simple_sieve(int limit)
{
char is_prime[limit + 1];
memset(is_prime, 1, limit + 1);
@tos-kamiya
tos-kamiya / main.rs
Last active October 27, 2021 04:16
Sieve of Eratosthenes in Rust
fn simple_sieve(limit: usize) -> Vec<usize> {
let mut is_prime = vec![true; limit + 1];
for n in 2 ..= limit {
if is_prime[n] {
for m in (n*n ..= limit).step_by(n) {
is_prime[m] = false;
}
}
}
@tos-kamiya
tos-kamiya / pandocでgfmなmarkdownをa4サイズのpdfにする(2021).md
Last active April 30, 2024 15:04
Pandocを使ってgfmなMarkdownをA4サイズのPDFにする(2021)

セマンティック・コミット・メッセージ

あなたをより良いプログラマーにする,コミットメセージのちょっとした変更.

フォーマット: <タイプ>(<スコープ>): <件名>

<スコープ>は省略可能.

@tos-kamiya
tos-kamiya / screenshot.png
Last active June 27, 2021 14:43
Open a window showing image of (desktop) wallpaper. For Gnome desktop. Requires `pqiv` and `gsettings` commands.
screenshot.png