Skip to content

Instantly share code, notes, and snippets.

View liuyu81's full-sized avatar

LIU Yu liuyu81

  • China
View GitHub Profile
@liuyu81
liuyu81 / c_extension_module.c
Created August 26, 2012 02:54
call Python callback from a non-python thread in a C extension module (in response to zed's demo, https://gist.github.com/3471699, and this question http://stackoverflow.com/questions/12116390/python-code-calls-c-library)
#include "Python.h" // should be before any standard headers
#include <errno.h>
#include <pthread.h>
static void*
non_python_thread(void *python_callback) {
//XXX without PyEval_InitThreads() it produces:
// Fatal Python error: PyEval_SaveThread: NULL tstate
//XXX with PyEval_InitThreads() it deadlocks!!
//XXX without PyGILState_*() (with/without PyEval_InitThreads()) it produces:
@liuyu81
liuyu81 / .gitignore
Created October 28, 2012 14:28
system call inspection with libsandbox (http://sourceforge.net/projects/libsandbox)
*.pyc
*.pyo
__pycache__
@liuyu81
liuyu81 / .gitignore
Last active December 14, 2015 05:19
Testbed for the sandbox policy from Richard's CodeRunner (https://github.com/trampgeek/CodeRunner)
*.pyc
*.pyo
__pycache__
distance.py
@liuyu81
liuyu81 / cgi_pipeline.py
Last active August 29, 2015 13:56
Python script for converting PHP key-value array to JSON dictionary
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SnapSearch.cgi
~~~~~~~~~~~~~~
:copyright: 2014 by `SnapSearch <https://snapsearch.io/>`_
:license: MIT, see LICENSE for more details.
:author: `LIU Yu <liuyu@opencps.net>`_
@liuyu81
liuyu81 / qqmusic_dl.py
Created November 23, 2015 13:40
QQ Music Downloader
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import requests
import sys
import time
from lxml import etree