Skip to content

Instantly share code, notes, and snippets.

@pn11
pn11 / emacs-wrapper.sh
Created Jun 18, 2021
Do not open Emacs in VSCode Terminal
View emacs-wrapper.sh
#!/bin/bash
if [ $TERM_PROGRAM = 'vscode' ]; then
code $*
else
exec emacsclient -t -a "" $*
fi
@pn11
pn11 / covid-19-Wako.ipynb
Last active May 2, 2021
covid-19-Wako.ipynb
View covid-19-Wako.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pn11
pn11 / colab-ssh.ipynb
Last active Jan 23, 2021
ngrok を使って Google Colab に SSH ログインする。 cf. https://qiita.com/hazigin/items/c291adf5dc9ccc13d11f
View colab-ssh.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pn11
pn11 / tab_json2md.py
Last active Jan 10, 2021
Convert Chrome tab list extracted from Android into a Markdown and a OneTab-importable format.
View tab_json2md.py
# In advance, tabs.json have to be extracted via ADB by following way. (See https://android.stackexchange.com/a/199496/340082 for detail.)
# adb forward tcp:9222 localabstract:chrome_devtools_remote
# wget -O tabs.json http://localhost:9222/json/list
import json
with open('tabs.json') as f:
tabs = json.load(f)
with open('tabs.md', 'w') as f:
f.write(f"# {len(tabs)} tabs in your Android Chrome\n\n")
@pn11
pn11 / 20210108-covid19-tokyo.ipynb
Created Jan 7, 2021
20210108-covid19-tokyo.ipynb
View 20210108-covid19-tokyo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pn11
pn11 / count_files.sh
Created Aug 30, 2020
Count files in a directory recursively with Bash
View count_files.sh
#!/bin/bash
# For Mac (Homebrew), use aliases below
#alias find=gfind
#alias sed=gsed
function count_files () {
num_files=$(gfind "$1" -maxdepth 1 -type f | wc -l)
echo "$1 ${num_files}"
@pn11
pn11 / hatenaoauth_example_py3.py
Last active Apr 6, 2020 — forked from soy-curd/hatenaoauth_example_py3.py
Pythonではてなの OAuth 対応 API を利用する(python3版)
View hatenaoauth_example_py3.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
フレームワークとして Flask(http://flask.pocoo.org/) を、OAuth ライブラリとして oauth2(http://pypi.python.org/pypi/oauth2/) を利用したサンプルプログラムです。
下のコードを保存して (oauth_consumer.py とします)、YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET となっている部分を自分の consumer_key, consumer_secret で置き換えます。(settings.pyに保存してください)
$ python oauth_consumer.py
... で起動してから http://localhost:5000 に Web ブラウザでアクセスして下さい。
+ 2015/10/25 python3用に書き換えました。
"""
@pn11
pn11 / download_images.py
Last active Aug 30, 2020
Download images from a website. keywords: scraping, requests, python
View download_images.py
import requests
import time
from tqdm import tqdm
base_url = 'http://xxxxx.xxx/{image_id}.jpg'
def get_image(image_id):
r = requests.get(base_url.format(image_id=image_id))
with open(f"{image_id}.jpg", 'wb') as f:
f.write(r.content)
View tmux.man.txt
TMUX(1) BSD General Commands Manual TMUX(1)
NAME
tmux — terminal multiplexer
SYNOPSIS
tmux [-2CluvV] [-c shell-command] [-f file] [-L socket-name]
[-S socket-path] [command [flags]]
DESCRIPTION
@pn11
pn11 / singleton.py
Last active Sep 17, 2019
Singleton in Python3
View singleton.py
import threading
class ThreadingSingleton:
_instance = None
_lock = threading.Lock()
def __init__(self):
print('__init__')
def __new__(cls):