Skip to content

Instantly share code, notes, and snippets.

View Petelin's full-sized avatar

lin Petelin

View GitHub Profile
@Petelin
Petelin / alloc.go
Created December 5, 2018 08:01
go堆外分配分区
# from https://www.zhihu.com/people/tou-gou-bao-da
package main
import (
"fmt"
"math"
"math/rand"
"reflect"
"runtime"
"sort"
@Petelin
Petelin / random_MT.cpp
Created November 15, 2018 02:34
random MT, with seed
#include <stdio.h>
#include <time.h>
#ifndef MERSENNE_TWISTER_H
#define MERSENNE_TWISTER_H
#define __STDC_LIMIT_MACROS
# define uint32_t unsigned int
#ifdef __cplusplus
extern "C" {
@Petelin
Petelin / random_plan9.cpp
Created November 4, 2018 16:49
random plan9
#include <u.h>
#include <libc.h>
/*
* algorithm by
* D. P. Mitchell & J. A. Reeds
*/
#define LEN 607
#define TAP 273
@Petelin
Petelin / runInSubprocss.go
Created July 25, 2018 08:08
run real job in subprocess
package main
import (
"fmt"
"os"
"os/exec"
"time"
)
func main() {
@Petelin
Petelin / gkill.sh
Created July 13, 2018 05:51
two greate tool to start proc, or kill proc by name
33 # search and kill
32 function gkill(){
31 filter=$1
30 exp=[${filter:0:1}]${filter:1}
29 echo '>ps aux | grep' $exp
28 echo $( ps aux | grep $exp --color=always | xargs -I % echo '\n' %)
27 echo "Kill?"
26 read Keypress
25 case "$Keypress" in
24 * ) kill $2 $args $(ps aux | grep $exp --color=always | awk '{print $2}');
@Petelin
Petelin / update_if_bigger.lua
Last active June 22, 2018 09:41
this lua script is used to in redis. it will set to the key if the value is bigger than the `updateat:{timestamp}`, if no udpateat founded update as normal
local a = redis.call('get',KEYS[1]);
if a and a:find("^updateat:") ~= nil then
-- this key already update by anther thread. so we test
if tonumber(string.sub(a, 10, string.len(a))) <= tonumber(KEYS[2]) then
return redis.call('set',KEYS[1], KEYS[3]);
end
return;
end
return redis.call('set',KEYS[1], KEYS[3]);
dash_id=xxxx
api_key=xxx
app_key=xxx
# 1. export
curl -X GET "https://app.datadoghq.com/api/v1/dash/${dash_id}?api_key=${api_key}&application_key=${app_key}" > dash.json
# 2. edit dash.json
move "graphs", "title", "description" up one level in the json hierarchy, from being beneath "dash" to being at the same level
@Petelin
Petelin / selfloop
Last active November 2, 2017 05:29
基于select+asynico的基础实现
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : petelin1120@gmail.com
# Date : 17/11/1 20:00
# Desc : ...
import types
from selectors import DefaultSelector, EVENT_WRITE, EVENT_READ
from collections import deque
@Petelin
Petelin / gist:1835fe063c38c01cf10a141736d14a9b
Created October 28, 2017 14:33
只用yield关键字, 纯python实现协程
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : zhangxiaolin
# E-mail : petelin1120@gmail.com
# Date : 16/11/3 16:03
# Desc : ...
import queue
from queue import Queue
import socket
@Petelin
Petelin / pre-commit
Created April 1, 2017 02:56
git 提交前pep8检查
(pycharm_ascle) [~]$ cat .git-templates/hooks/pre-commit
#!/usr/bin/env bash
git diff --cached -- '*.py' | `which pep8` --max-line-length=119 --show-source --diff
if [ $? -gt 0 ]; then
echo
echo '--------'
echo 'Lint check failed.'
exit 1