Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

guerbai

🎯
Focusing
View GitHub Profile
@guerbai
guerbai / en_US
Created Oct 10, 2021
fcitx-diagnose
View en_US
# 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 Feb 16, 2020
[并发洗数go]
View channel.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 Feb 3, 2020
es查询收集 #ElasticSearch
View count_distinct.json
{
"size": 0,
"aggs": {
"path": {
"filter": {
"bool": {
"filter": [
{"term": {"file_type": 150}}
]
}
View 是否有该进程.py
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:
View read_csv.py
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'])
View slice-of-struct-sort-by-field.go
package main
import (
"fmt"
"github.com/bradfitz/slice"
)
type ArtistUidInfo struct {
ArtistId int64
@guerbai
guerbai / calculate.go
Last active Jun 12, 2019
calculate函数,闭包与传函数
View calculate.go
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 Jun 3, 2019
是否修改数据的值
View array_modified.go
// 传址会修改原数据
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 Jun 2, 2019
Keras mnist准备工作 #Keras
View keras_mnist_init.py
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 Jun 2, 2019
sql with example #BigQuery
View sql_with_example.sql
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