Skip to content

Instantly share code, notes, and snippets.

View weedge's full-sized avatar
🍀
coding at home

weedge weedge

🍀
coding at home
View GitHub Profile
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"github.com/apache/rocketmq-client-go/v2"
package main
import (
"context"
"encoding/json"
"log"
"os"
"os/signal"
"strconv"
"syscall"
-- author: weedge
-- params: KEYS[1] user asset key
-- params: KEYS[2] event msg key
-- params: ARGV[1] incr asset num eg:1,-1
-- params: ARGV[2] user asset key ttl
-- params: ARGV[3] event msg key ttl
-- return 1:操作成功, 0:无操作,-1:缓存资产不存在,-2:资产不足,
-- debug:
-- redis-cli --ldb --eval user_asset_change.redis.lua I.asset.{100} M.asset.{100}.`ksuid` , 100 86400 86400
-- redis-cli -c -p 26383 --ldb --eval user_asset_change.redis.lua I.asset.{100} M.asset.{100}.`ksuid` , 100 86400 86400
// ¥¥¥ show me the money ¥¥¥
// author: weedge
// desc: redis change asset tx demo
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
show engines;
show databases;
drop database pay;
create database pay ;
use pay;
drop table `pay`.`user_asset`;
CREATE TABLE `user_asset`
(
`userId` bigint unsigned NOT NULL DEFAULT '0',
`assetCn` bigint unsigned NOT NULL DEFAULT '0',
@weedge
weedge / db-mysql-asset-demo.go
Last active December 17, 2022 12:07
change
package main
import (
"context"
"errors"
"fmt"
"log"
"sync"
"time"
@weedge
weedge / scala_vim.sh
Created October 15, 2017 15:18
scala vim 高亮插件
#!/bin/bash
mkdir -p ~/.vim/{ftdetect,indent,syntax}
for d in ftdetect indent syntax ; do
curl -o ~/.vim/$d/scala.vim https://raw.githubusercontent.com/gchen/scala.vim/master/scala.vim
done
@weedge
weedge / spinvsmutex2.c
Last active October 16, 2017 05:30
临界区执行时间长的情况下,spin_lock 执行效率低于 mutex_lock
//Name: spinvsmutex2.c
//http://www.parallellabs.com/2010/01/31/pthreads-programming-spin-lock-vs-mutex-performance-analysis/
//Source: http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_Locks
//Compile(spin lock version): gcc -o spin -DUSE_SPINLOCK spinvsmutex2.c -lpthread
//Compile(mutex version): gcc -o mutex spinvsmutex2.c -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/syscall.h>
@weedge
weedge / spinlockvsmutex1.cpp
Last active October 12, 2017 16:46
理解spin_lock, mutex_lock,比较两者
// Name: spinlockvsmutex1.cpp
//http://www.parallellabs.com/2010/01/31/pthreads-programming-spin-lock-vs-mutex-performance-analysis/
// Source: http://www.alexonlinux.com/pthread-mutex-vs-pthread-spinlock
// Compiler(spin lock version): g++ -o spin_version -DUSE_SPINLOCK spinlockvsmutex1.cpp -lpthread
// Compiler(mutex version): g++ -o mutex_version spinlockvsmutex1.cpp -lpthread
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <errno.h>
#include <sys/time.h>
@weedge
weedge / videoToPlayerFromServerSocket.py
Last active December 18, 2022 10:00
video stream to server socket, play this stream from socket (use VLC in MAC)
import socket
import subprocess
# Start a socket listening for connections on 0.0.0.0:8000 (0.0.0.0 means
# all interfaces)
server_socket = socket.socket()
server_socket.bind(('0.0.0.0', 8000))
server_socket.listen(0)
# Accept a single connection and make a file-like object out of it