Skip to content

Instantly share code, notes, and snippets.

LEAK_CHECK_CP=$(grep "definitely lost:" %X86_64_BUILD_DIR_NAME%/leak_check_cp --after-context=2 | tr '\n' ' ' | sed -e 's/^==[0-9]*==\s*//' | sed -e 's/\s*==[0-9]*==\s*/ | /g' | sed -e 's/in\s[0-9]*\sblocks//g')
LEAK_CHECK_EN=$(grep "definitely lost:" %X86_64_BUILD_DIR_NAME%/leak_check_en --after-context=2 | tr '\n' ' ' | sed -e 's/^==[0-9]*==\s*//' | sed -e 's/\s*==[0-9]*==\s*/ | /g' | sed -e 's/in\s[0-9]*\sblocks//g')
LEAK_CHECK_VR=$(grep "definitely lost:" %X86_64_BUILD_DIR_NAME%/leak_check_vr --after-context=2 | tr '\n' ' ' | sed -e 's/^==[0-9]*==\s*//' | sed -e 's/\s*==[0-9]*==\s*/ | /g' | sed -e 's/in\s[0-9]*\sblocks//g')
require 'aws-sdk-s3'
require 'net/http'
require 'pry'
s3 = Aws::S3::Resource.new(region:'ap-northeast-1')
obj = s3.bucket('threal-test').object('only_1_min')
# Replace BucketName with the name of your bucket.
# Replace KeyName with the name of the object you are creating or replacing.
url = URI.parse(obj.presigned_url(:put, expires_in: 3600))
@hfyeh
hfyeh / NEON
Last active December 21, 2019 08:14
Halide
void gemm4x4_vec(float *a, int sa, float *b, int sb, float *c, int sc)
{
// vaddq_f32
// vmulq_f32
// vld1q_f32(a)
float32x4_t vb[4];
size_t x, y, k;
for(int i=0; i<4; i++){
@hfyeh
hfyeh / main2.c
Created July 2, 2019 17:26
IEEE 754 float 2
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
// Check float and character size
if (sizeof(float) != 4){
printf("Float is not 32 bits on your machine!");
exit(-1);
}
@hfyeh
hfyeh / main1.c
Last active July 2, 2019 17:25
IEEE 754 float 1
#include <stdio.h>
#include <math.h>
int main(){
float f1 = 2.999999;
float f2 = 2.9999999;
printf("floor(f1), 20 digital points: %10.20f\n", floor(f1));
printf("floor(f2), 20 digital points: %10.20f\n", floor(f2));
}
@hfyeh
hfyeh / gen_qrcode.py
Last active January 11, 2019 04:47
Generate QR Code from file in Python
import qrcode
f = open('qrcode.txt')
for line in f:
line = line.strip()
qr = qrcode.QRCode(
version=4,
error_correction=qrcode.constants.ERROR_CORRECT_L,
@hfyeh
hfyeh / ar_migrate.rb
Created June 24, 2018 09:44 — forked from icyleaf/ar_migrate.rb
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
@hfyeh
hfyeh / monit-redis.conf
Created June 4, 2018 06:28
Multiple redis server in one machine
# /etc/monit/conf.d/
check process redis-master
with pidfile "/var/run/redis/redis-master.pid"
start program = "/usr/local/bin/redis-server /etc/redis/redis-master.conf"
stop program = "/usr/local/bin/redis-cli -p 6379 shutdown"
check process redis-slave-1
with pidfile "/var/run/redis/redis-slave-1.pid"
start program = "/usr/local/bin/redis-server /etc/redis/redis-slave-1.conf"
stop program = "/usr/local/bin/redis-cli -p 6380 shutdown"
check process redis-store
@hfyeh
hfyeh / parallel.rb
Created October 4, 2017 06:17
single process v.s. multi process (from ruby china)
range1 = 0...50_000_000
range2 = 50_000_000...100_000_000
number = 99_999_999
puts "Parent #{Process.pid}"
fork { puts "Child1 #{Process.pid}: #{range1.to_a.index(number)}" }
fork { puts "Child2 #{Process.pid}: #{range2.to_a.index(number)}" }
Process.wait
# time ruby parallel.rb
# parent 20434
@hfyeh
hfyeh / nginx.conf
Last active November 9, 2017 09:21
nginx configuration
user www-data;
# worker數量,與核心數同
worker_processes 4;
pid /run/nginx.pid;
# Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'
# or using /etc/security/limits.conf
#一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致.
worker_rlimit_nofile 65535;