Skip to content

Instantly share code, notes, and snippets.

View achimnol's full-sized avatar

Joongi Kim achimnol

View GitHub Profile
@achimnol
achimnol / run-altdocker.sh
Created January 20, 2019 05:48
Running alternative Docker daemon on the same host
#! /bin/bash
# References:
# - https://stackoverflow.com/questions/32334167/is-it-possible-to-start-multiple-docker-daemons-on-the-same-machine
# - https://docs.docker.com/engine/reference/commandline/dockerd/
# First you need to have Docker 18.09+ and the bridge-utils package installed.
ROOT=/opt/altdocker
: ${bridge=altdocker0}
: ${base=$ROOT/$bridge}
@achimnol
achimnol / test.py
Last active January 10, 2018 09:35
async generator closing
import asyncio
import pytest
@pytest.mark.asyncio
async def test_close_asyncgen():
loop = asyncio.get_event_loop()
async def mygen():
print('mygen: 0-begin')
@achimnol
achimnol / graphql-sample.py
Last active September 14, 2017 10:24
GraphQL Sample in Python
import asyncio
import base64
import enum
import secrets
from pprint import pprint
import graphene
from graphql.execution.executors.asyncio import AsyncioExecutor
import ctypes
import ctypes.util
_libcuda = ctypes.CDLL(ctypes.util.find_library('cudart'))
if __name__ == '__main__':
# You should put the path to the CUDA toolkit library into LD_LIBRARY_PATH envvar
# or into the system-wide configuration at /etc/ld.so.conf.d/.
count = ctypes.c_int(0)
@achimnol
achimnol / cuda.conf
Last active September 25, 2016 15:32
An upstart configuration for NVIDIA CUDA device initialization without X environments (derived from Sangjin Han's init.d script)
description "CUDA initialization without X environments"
start on runlevel [2345]
stop on runlevel [!2345]
pre-start script
DRIVER=nvidia
HOLD_GPU=/usr/local/bin/hold_gpu.py
[ -x "$HOLD_GPU" ] || { echo "$HOLD_GPU is missing or not executable!"; exit 1; }
@achimnol
achimnol / sharelatex.conf
Last active July 30, 2016 19:04
sharelatex SSL reverse-proxy setting
server {
...
ssl on;
# Some mobile browsers require full-chain certificates.
ssl_certificate /var/lib/sharelatex/ssl/myserver-fullchain-cert.pem;
ssl_certificate_key /var/lib/sharelatex/ssl/myserver-privkey.pem;
ssl_session_timeout 3m;
# http basic auth is no longer required since sharelatex now only allows user addition by admins.
@achimnol
achimnol / cache_file.py
Last active December 18, 2015 02:48
A simple LRU-based file cache, assuming that a RAM-disk is present at ~/ramdisk.
import os, time, shutil, heapq
MAX_CACHE_MB = 200
_CACHED_FILES = []
_CACHED_SIZE = None # in bytes
def cache_file(filename):
'''
Automatically maintain a cached version of the given filename.
@achimnol
achimnol / mcbot.conf
Created March 15, 2013 11:52
An upstart configuration for Minecraft and mcbot (https://github.com/achimnol/mcbot) daemonization
description "Minecraft Chatting Bot Daemon"
start on started minecraft
stop on stopping minecraft
chdir /home/daybreaker/minecraft/bin/mcbot
console log
pre-start script
sleep 1
@achimnol
achimnol / create-hg-git-rev-mapping.py
Created August 23, 2012 16:29
A commit ID mapping creator for a hg repository and a (converted) git repository based on commit timestamps
#! /usr/bin/env python3
import os, sys
import subprocess
from datetime import datetime
def execute(cmd):
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
stdout, stderr = proc.communicate()
return stdout.decode('utf-8')
@achimnol
achimnol / gist:3405022
Created August 20, 2012 15:08
An init.d script for CUDA device initialization without X environments (by Sangjin Han)
#!sh
#!/bin/bash
#
# Startup/shutdown script for nVidia CUDA
#
# chkconfig: 345 80 20
# description: Startup/shutdown script for nVidia CUDA
# Source function library.
#. /etc/init.d/functions