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
@weedge
weedge / photographTOServerSocket.py
Last active September 29, 2017 13:58
simple photograph server
import io
import socket
import struct
#u should do this:
# pip install --upgrade pip
# pip install image
from PIL import Image
# NOTICE:
# The server script should be run first (don't run in pi)·
# to ensure there’s a listening socket ready to accept a connection from the client script
@weedge
weedge / photographToClientSocket.py
Last active September 29, 2017 14:03
simple client photograph to socket in PI (use picamera)
import io
import socket
import struct
import time
import picamera
from PIL import Image
import cv2
import numpy as np
def photographToFile():
@weedge
weedge / videoToClientSocket.py
Created September 29, 2017 16:15
simple video op by using picamera
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# look this: http://picamera.readthedocs.io/en/release-1.2/recipes1.html
import io
import os
import sys
import random
import time
import struct
@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
@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 / 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 / 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 / db-mysql-asset-demo.go
Last active December 17, 2022 12:07
change
package main
import (
"context"
"errors"
"fmt"
"log"
"sync"
"time"
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',
// ¥¥¥ show me the money ¥¥¥
// author: weedge
// desc: redis change asset tx demo
package main
import (
"context"
"encoding/json"
"errors"
"fmt"