Skip to content

Instantly share code, notes, and snippets.

View zhongwencool's full-sized avatar
🌊

zhongwencool zhongwencool

🌊
  • China Guǎng Zhōu
View GitHub Profile
#!/bin/bash
# Pull this file down, make it executable and run it with sudo
# wget https://raw.github.com/gist/5487621/build-erlang-r16b.sh
# chmod u+x build-erlang-r16b.sh
# sudo ./build-erlang-r16b.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
@zhongwencool
zhongwencool / color_console.h
Created June 23, 2014 04:26
Hacker rain compile by g++ -std=c++0x hackerRain.cpp
#pragma once
#include <iostream>
#include <windows.h>
inline std::ostream& blue(std::ostream &s)
{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
return s;
@zhongwencool
zhongwencool / timing_wheel.erl
Created June 26, 2014 06:54
一个简单的分层时间轮实现:类似于3维数组实现时钟
%%%-------------------------------------------------------------------
%%% @author zhongwencool@gmail.com
%%% @doc 一个简单的分层时间轮实现:类似于3维数组实现时钟
%%% 根据 http://www.embeddedlinux.org.cn/RTConforEmbSys/5107final/LiB0071.html 实现
%%% 1.时钟原理说明:
%%% 1.1. 初始化一个三层时间轮:秒刻盘:0~59个SecList, 分刻盘:0~59个MinList, 时刻盘:0~12个HourList;
%%% 1.2. SecTick由外界推动,每跳一轮(60格),SecTick复位至0,同时MinTick跳1格;
%%% 1.3. 同理MinTick每跳一轮(60格),MinTick复位至0,同时HourTick跳1格;
%%% 1.4. 最高层:HourTick跳一轮(12格),HourTick复位至0,一个时间轮完整周期完成.
%%% 2.事件原理说明:
@zhongwencool
zhongwencool / cloud_server.erl
Last active October 1, 2019 04:49
Book Cloud Node :test connect nodes.
%%%-------------------------------------------------------------------
%%% @author <zhongwencool@gmail.com>
%%% @doc run :
%%% erl -name cloud_server@127.0.0.1 -pa "../ebin/" -setcookie best -run cloud_server start_link
%%% erl -name server0@127.0.0.1 -pa "../ebin/" -run deal_book_server -extra server0@127.0.0.1
%%% erl -name server1@127.0.0.1 -pa "../ebin/" -run deal_book_server -extra server1@127.0.0.1
%%% .......
%%% erl -name server9@127.0.0.1 -pa "../ebin/" -run deal_book_server -extra server9@127.0.0.1
%%% Created : 11 Apr 2014
%%%-------------------------------------------------------------------

#git使用记录 ##1. Config相关:

  • 用户名:

    git config --global user.name "zhongwencool"
  • 用户邮箱

%%%-------------------------------------------------------------------
%%% @author zhongwencool@gmail.com
%%% @copyright (C) 2016, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 06. 一月 2016 18:30
%%%-------------------------------------------------------------------
-module(hex).
@zhongwencool
zhongwencool / httpoison_request_response_example.ex
Last active January 27, 2021 16:02
maxwell vs httpoison vs httppotion examples
defmodule Httpoison.GitHub do
use HTTPoison.Base
def process_url(url) do
"https://api.github.com" <> url
end
def process_request_headers(headers) do
Dict.put headers, :"User-Agent", "github-httpoison"
end
@zhongwencool
zhongwencool / test.erl
Last active July 25, 2016 20:40
Find top n items in a unordered list
-module(test).
-compile(export_all).
%% API
run_all_sorted_sublist(List, Num) ->
lists:sublist(lists:sort(
fun({_,A,_},{_,B,_}) -> A > B end,
List), Num).
run_gb_trees(List, Num) ->
@zhongwencool
zhongwencool / zoo.app
Last active September 11, 2016 10:39
supervisor child_spec shutdown mechanism doesn't work when child process crash itself.
{application,zoo,
[{description,"Warm and lovely zoo"},
{vsn,"0.1.0"},
{registered,[]},
{mod,{zoo_app,[]}},
{applications,[kernel,stdlib, sasl]},
{env,[]},
{modules,[zoo_app,zoo_keeper,zoo_sup]}]}.
@zhongwencool
zhongwencool / mnesia_read_test.erl
Created October 13, 2016 08:33
[test] mnesia find object without transaction.
-module(mnesia_read_test).
-include_lib("stdlib/include/ms_transform.hrl").
-include_lib("stdlib/include/qlc.hrl").
%% API
-compile(export_all).
-record(person, {name, sex, age, height}).
-define(PERSON, person).