Skip to content

Instantly share code, notes, and snippets.

View guerbai's full-sized avatar
🎯
Focusing

guerbai

🎯
Focusing
View GitHub Profile
@guerbai
guerbai / en_US
Created October 10, 2021 14:55
fcitx-diagnose
# System Info:
1. `uname -a`:
Linux arch 5.14.9-arch2-1 #1 SMP PREEMPT Fri, 01 Oct 2021 19:03:20 +0000 x86_64 GNU/Linux
2. `lsb_release -a`:
LSB Version: 1.4
Distributor ID: Arch
Description: Arch Linux
@guerbai
guerbai / channel.go
Created February 16, 2020 02:30
[并发洗数go]
var MAX_PARALLEL = 50
var sem = make(chan int, MAX_PARALLEL)
var f = "./ids.csv"
func bizFunc(id int64) {
defer func(){<-sem}()
// biz code.
}
func parallelWork() {
@guerbai
guerbai / count_distinct.json
Last active February 3, 2020 07:47
es查询收集 #ElasticSearch
{
"size": 0,
"aggs": {
"path": {
"filter": {
"bool": {
"filter": [
{"term": {"file_type": 150}}
]
}
import subprocess
def progress_exist(name):
ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
job = subprocess.Popen(['grep', name], stdin=ps.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ps.stdout.close()
out, err = job.communicate()
out = out.decode()
no_grep_out = 0
if len(out) > 0:
@guerbai
guerbai / read_csv.py
Last active February 4, 2020 02:59
csv
import csv
filename = './test.csv'
with open(filename, 'r') as f:
data_csv = csv.DictReader(f, delimiter=',')
for data in data_csv:
print (data['clip_id'])
@guerbai
guerbai / slice-of-struct-sort-by-field.go
Created October 12, 2019 10:15
[slice常用方法] #go
package main
import (
"fmt"
"github.com/bradfitz/slice"
)
type ArtistUidInfo struct {
ArtistId int64
@guerbai
guerbai / calculate.go
Last active June 12, 2019 03:38
calculate函数,闭包与传函数
type operate func(x, y int) int
func calculate(x int, y int, op operate) (int, error) {
if op == nil {
return 0, error.New("no op")
}
return op(x, y), nil
}
var add = func (x, y int) int {
@guerbai
guerbai / array_modified.go
Created June 3, 2019 03:44
是否修改数据的值
// 传址会修改原数据
func main() {
x := [3]int{1,2,3}
func(arr *[3]int) {
(*arr)[0] = 7
fmt.Println(arr) // &[7 2 3]
}(&x)
fmt.Println(x) // [7 2 3]
}
@guerbai
guerbai / keras_mnist_init.py
Created June 2, 2019 05:13
Keras mnist准备工作 #Keras
img_rows, img_cols = 28, 28
num_classes = 10
def prep_data(raw):
y = raw[:, 0]
out_y = keras.utils.to_categorical(y, num_classes)
x = raw[:,1:]
num_images = raw.shape[0]
out_x = x.reshape(num_images, img_rows, img_cols, 1)
@guerbai
guerbai / sql_with_example.sql
Created June 2, 2019 05:11
sql with example #BigQuery
WITH time AS
(
SELECT DATE(block_timestamp) AS trans_date
FROM `bigquery-public-data.crypto_bitcoin.transactions`
)
SELECT COUNT(1) AS transactions,
trans_date
FROM time
GROUP BY trans_date
ORDER BY trans_date