Skip to content

Instantly share code, notes, and snippets.

View yanxurui's full-sized avatar

Xurui Yan yanxurui

View GitHub Profile
@yanxurui
yanxurui / SplClassLoader.php
Created July 22, 2016 02:21 — forked from jwage/SplClassLoader.php
Add MIT license.
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
@yanxurui
yanxurui / logging_right1.py
Last active April 15, 2017 03:31
Logging module's FileHandler doesn't write into the file
import logging
logger = logging.getLogger('spam_application')
logger.setLevel(logging.DEBUG) # default will not show log messages whose level is under warning
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
fh = logging.FileHandler('spam.log')
fh.setLevel(logging.DEBUG)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
pid logs/nginx_upload.pid;
events {
worker_connections 1024;
}
http {
lua_package_path '/usr/local/lib/lua/5.1/?.lua;/blah/?.lua;;';
server {
listen 8001;
@yanxurui
yanxurui / du.py
Last active March 31, 2017 09:20
find your biggest folder
#!/usr/bin/env python
# coding=utf-8
import os
import sys
import pdb
from os import path
import argparse
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
@yanxurui
yanxurui / test_websocket.sh
Created April 18, 2017 13:18 — forked from higebu/test_websocket.sh
Test WebSocket with curl
curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: https://www.websocket.org" https://echo.websocket.org
@yanxurui
yanxurui / dummy-web-server.py
Created April 18, 2017 15:34 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@yanxurui
yanxurui / libev_client.c
Last active June 4, 2017 04:50
chat room example based on libev
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <ev.h>
#define BUFFER_SIZE 1024
@yanxurui
yanxurui / pthread_client.c
Created June 4, 2017 04:53
chat room example based on multithread
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
#define BUFFER_SIZE 1024
@yanxurui
yanxurui / libev_model.c
Created June 4, 2017 04:55
libev steps for beginners
/*all watcher callbacks have a similar signature
callback arguments:
1. event loop pointer, or use EV_P_ macro
2. the registered watcher structure
3. a bitset of received events
*/
static void my_cb (struct ev_loop *loop, ev_io *w, int revents)
{
// ...
// stop watching for events at any time by calling the corresponding stop function ev_TYPE_stop (loop, watcher *)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <errno.h>