Skip to content

Instantly share code, notes, and snippets.

@physacco
physacco / README.md
Last active December 27, 2023 09:05
Python 3 extension example

Python 3 extension example

Build

python3 setup.py build

Output: build/lib.macosx-10.11-x86_64-3.5/hello.cpython-35m-darwin.so

Run

@physacco
physacco / firefox-proxy-config.md
Last active December 2, 2023 18:40
firefox配置socks5代理的方法

配置socks5代理的方法

打开 about:config, 修改下面这些项目:

network.proxy.type                       1
network.proxy.socks                      127.0.0.1
network.proxy.socks_port                 1080
network.proxy.socks_remote_dns           true
network.proxy.socks_version              5

network.proxy.no_proxies_on localhost, 127.0.0.1

@physacco
physacco / CMakeLists.txt
Last active November 27, 2023 19:12
MsgPack sample programs.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
PROJECT(msgpack_test)
SET(CMAKE_CXX_FLAGS_DEBUG "-g -std=c++11")
SET(EXECUTABLES test_vector test_stream test_class test_array test_map1 test_map2)
FOREACH(EXE ${EXECUTABLES})
ADD_EXECUTABLE(${EXE} "${EXE}.cpp")
TARGET_LINK_LIBRARIES(${EXE} msgpack)
@physacco
physacco / CMakeLists.txt
Created July 8, 2016 02:44
Android NDK hello-world program.
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
PROJECT(hello)
SET(PROJECT_ROOT_PATH "${CMAKE_SOURCE_DIR}")
SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin")
SET(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
ADD_EXECUTABLE(hello hello.cpp)
@physacco
physacco / pyc2xml.py
Created June 18, 2013 02:37
Dump a .pyc file to XML, with decompilation.
import pdb
import cgi
import dis
import time
import struct
import marshal
def dump_code_object(code, ident=0):
print '%s<code_object>' % (' '*ident,)
ident += 2
@physacco
physacco / test_pcap.c
Created April 9, 2013 08:49
A "hello world" example for libpcap.
#include <stdio.h>
#include <stdlib.h>
#include <pcap/pcap.h>
/* callback function when packet have captured */
static void mycb(u_char *user,
const struct pcap_pkthdr *h, const u_char *packet)
{
static int count = 1;
printf("Packet %d:\n", count);
@physacco
physacco / tcp_keepalive.c
Created June 16, 2013 17:10
Play with TCP socket options related to keep-alive.
/* tcp_keepalive.c
*
* References:
* http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html
* http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@physacco
physacco / resize_chrome.sh
Created July 7, 2016 02:39
Resize Google Chrome browser on Mac OS X
#!/bin/bash
osascript -e 'tell application "Google Chrome"' -e 'set bounds of front window to {1, 1, 1280, 640}' -e 'end tell'
@physacco
physacco / hash2array.lua
Created February 28, 2013 03:10
This gist presents 2 Lua functions for converting hash to array and vice versa. This is a common task in Redis Lua scripting.
-- $ lua hash2array.lua
-- print a table that contains numbers and strings only
local f_log_hash = function(hash, name)
if name ~= nil then
print(name .. ':')
end
for k, v in pairs(hash) do
print(k, ' => ', v)
end
@physacco
physacco / test_sjcl.js
Created March 25, 2013 13:36
Basic usage example of SJCL.
// Basic usage example of SJCL.
// Tested on firefox 20.0 and nodejs 0.8.
// Refer to: http://crypto.stanford.edu/sjcl/
var sjcl = require("./sjcl");
var plaintext = "大丈夫だ、問題ない";
var encrypted = sjcl.encrypt("password", plaintext);
console.log(encrypted);
var decrypted = sjcl.decrypt("password", encrypted);
console.log(plaintext == decrypted);