Skip to content

Instantly share code, notes, and snippets.

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include <sched.h>
# Change YOUR_TOKEN to your prerender token and uncomment that line if you want to cache urls and view crawl stats
# Change example.com (server_name and in the rewrite rule) to your website url
# Change /path/to/your/root to the correct value
server {
listen 80;
server_name example.com;
root /path/to/your/root;
index index.html;
@chaizhenhua
chaizhenhua / lremzadd.lua
Last active April 19, 2017 20:31
redis lua script for reliable async task framwork
-- lremzadd source destination member score [member score ...]
local i = 3
local ret = 0
while KEYS[i] do
local x = redis.call("LREM", KEYS[1], 1, KEYS[i])
if x > 0 then
ret = ret + redis.call("ZADD", KEYS[2], KEYS[i+1], KEYS[i])
end
i = i + 2
@chaizhenhua
chaizhenhua / a.rb
Created January 9, 2014 14:49
1. rails c > A::A.poll > A::B.poll > A::A.poll > ... 2. run sidekiq 3. open sidekiq web and enqueue all scheduled job then sidekiq crashed
# /lib/a/a.rb
module A
class A < Base
include Handler::Poller
end
end
@chaizhenhua
chaizhenhua / gist:5563743
Created May 12, 2013 14:22
git stash pop revert
for ref in `git fsck --unreachable | grep commit | cut -d' ' -f3`; do git show --summary $ref; done | less
git filter-branch --commit-filter '
if [ "$GIT_COMMITTER_NAME" = "<Old Name>" ];
then
GIT_COMMITTER_NAME="<New Name>";
GIT_COMMITTER_EMAIL="<New Email>";
GIT_AUTHOR_NAME="<New Name>";
GIT_AUTHOR_EMAIL="<New Email>";
git commit-tree "$@";
else
git commit-tree "$@";
export PROMPT_COMMAND=__git_prompt
__git_prompt ()
{
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan