Skip to content

Instantly share code, notes, and snippets.

View junnplus's full-sized avatar

Jun junnplus

View GitHub Profile
@Ma233
Ma233 / daemonize.py
Last active October 13, 2024 17:35
double fork in python
# encoding: utf-8
import os
import sys
import time
import atexit
from signal import SIGTERM
'''
A daemon class referred from
`http://www.jejik.com/files/examples/daemon.py`
@tiann
tiann / auto_switch_kb.py
Created December 2, 2015 06:51
auto switch keyboard to english in specific applications
#! /usr/bin/env python
# coding: utf-8
'''
auto switch keyboard between different applications
if you want to change the app list, modify the var 'ignore_list'
'''
from AppKit import NSWorkspace, NSWorkspaceDidActivateApplicationNotification, NSWorkspaceApplicationKey
@anqxyr
anqxyr / archived
Last active July 5, 2018 15:08
Create EPUB files with Python
The gist that used to be here has since been implemented as a complete pip-installable package: https://github.com/anqxyr/mkepub
This notice is left here as a courtesy to the people who starred/bookmarked this gist in the past.
@tonyseek
tonyseek / ext.py
Last active April 6, 2019 12:54
Fixes the nonstandard OAuth interface of Tencent WeChat with Flask-OAuthlib.
from .weixin_compat import fixup_weixin_oauth
oauth = OAuth()
weixin = oauth.remote_app(
'weixin',
app_key='WEIXIN',
request_token_params={'scope': 'snsapi_base'},
base_url='https://api.weixin.qq.com',
authorize_url='https://open.weixin.qq.com/connect/oauth2/authorize',
access_token_url='https://api.weixin.qq.com/sns/oauth2/access_token',
@zhaoyao
zhaoyao / double_fork_trick.md
Last active April 2, 2021 16:18
double fork trick

避免僵尸进程出现.

如果fork后不进行waitwaitpid,那么子进程将会成会僵尸进程。double fork后, second child成为孤儿进程,由init负责后续的清理工作。

#include <stdio.h>
#include <unistd.h> 
#include <stdlib.h>
#include <sys/wait.h>