Skip to content

Instantly share code, notes, and snippets.

View unbit's full-sized avatar

Unbit unbit

View GitHub Profile
#include <SDL2/SDL.h>
#include <math.h>
#define FREQ 44100
struct note_to_play
{
Uint8 *data;
Uint32 len;
Uint32 offset;
#include <stdio.h>
struct vector3 {
float x;
float y;
float z;
};
struct vector3 vector3_add(struct vector3 v0, struct vector3 v1) {
struct vector3 new_vec;
using System;
using System.Collections.Generic;
namespace HuffmanTest
{
class Node
{
public Node Left;
public Node Right;
browser = webdriver.Firefox()
browser.get('http://google.com')
print(browser.page_source)
input_search = browser.find_element_by_id('lst-ib')
input_search.send_keys('do a barrel roll', Keys.ENTER)
#input_submit = browser.find_element_by_name('btnG')
#input_submit.click()
@unbit
unbit / router_remoteuser.c
Last active August 29, 2015 14:23
uWSGI router_remoteuser plugin
#include <uwsgi.h>
/*
extract REMOTE_USER from Authorization header
[uwsgi]
plugin = router_remoteuser
route-run = remoteuser:
route-run = log:${REMOTE_USER}
@unbit
unbit / gist:5d5bd97a56ca28d47548
Created November 21, 2014 08:22
pypy traceback
RPython traceback:
File "rpython_jit_metainterp_compile.c", line 20935, in send_loop_to_backend
File "rpython_jit_backend_x86_assembler.c", line 1854, in Assembler386_assemble_loop
File "rpython_jit_backend_x86_assembler.c", line 4804, in Assembler386__assemble
File "rpython_jit_backend_x86_regalloc.c", line 1730, in RegAlloc_walk_operations
File "rpython_jit_backend_x86_assembler.c", line 29896, in Assembler386_threadlocalref_get
@unbit
unbit / spinningfifo.c
Created October 21, 2014 03:49
spinningfifo uWSGI plugin
#include <uwsgi.h>
static int spinningfifo_hook(char *arg) {
int fd;
char *space = strchr(arg, ' ');
if (!space) {
uwsgi_log("invalid hook spinningfifo syntax, must be: <file> <string>\n");
return -1;
}
*space = 0;
@unbit
unbit / vassalchroot.c
Created October 6, 2014 08:13
vassalchroot uWSGI plugin
#include <uwsgi.h>
static void vassal_chroot_hook(struct uwsgi_instance *ui) {
// first of all get my username
struct passwd *pw = getpwuid(ui->uid);
if (!pw) {
uwsgi_log("unable to get username\n");
exit(1);
}
@unbit
unbit / gist:7970e4faa5f5edc108ba
Created July 16, 2014 16:04
uWSGI log encoder example
#include <uwsgi.h>
static char *log_encoder_add_worker(struct uwsgi_log_encoder *ule, char *msg, size_t len, size_t *rlen) {
char *buf = NULL;
// 64 bytes for worker id should be enough, btw the buffer will be adapted automatically
struct uwsgi_buffer *ub = uwsgi_buffer_new(len + 64);
// add current pid
if (uwsgi_buffer_num64(ub, getpid())) goto end;
// add a space
if (uwsgi_buffer_byte(ub, ' ')) goto end;
@unbit
unbit / gist:9207516
Created February 25, 2014 11:52
Embedding PyPy in C/C++
call rpython_startup_code(); for initializing
call pypy_setup_home(char *home, int debug); for setting the python home (returns non-zero on error, you can call it multiple times until it succeed)
call pypy_execute_source(char *code); execute the python code (IMPORTANT: GIL is still not set here)
call pypy_init_threads(); initialize GIL
finally call pypy_thread_attach(); in each additional pthread you need to register to python (this function is not thread safe, you should call it under a mutex)