Skip to content

Instantly share code, notes, and snippets.

@byyam
byyam / workdays.go
Last active May 29, 2025 10:48
get workdays
package workdays
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"time"
@byyam
byyam / fifo_cache.cpp
Created October 24, 2019 15:11
fifo cache demo
#include "fifo_cache.hpp"
tFifoCache::~tFifoCache()
{
if (p_cache_buffer != reinterpret_cast<char *>(-1))
{
int nRet = ::shmdt(p_cache_buffer);
if (0 != nRet)
{
@byyam
byyam / pthread_semaphore.cpp
Created October 24, 2019 15:09
pthread_semaphore
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <semaphore.h>
#define NUM 5
int queue[NUM];
sem_t blank_number, product_number;
@byyam
byyam / pthread_producer_consumer.cpp
Created October 24, 2019 15:08
pthread_producer_consumer
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
struct msg {
struct msg *next;
int num;
};
@byyam
byyam / pthread_mutex.cpp
Created October 24, 2019 15:07
pthread_mutex
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#define NLOOP 5000
pthread_mutex_t counter_mutex = PTHREAD_MUTEX_INITIALIZER;
int counter;
@byyam
byyam / coroutine_demo.cpp
Created October 24, 2019 15:06
coroutine cpp
#include <stdio.h>
#include <ucontext.h>
#include <list>
static void one();
static void two();
static void three();
static ucontext_t ctx1;
static ucontext_t ctx2;
@byyam
byyam / __init__.py
Created October 24, 2019 15:04
mysql py
#####
@byyam
byyam / loop.cpp
Created October 24, 2019 14:59
loop
#include <stdio.h>
#define ROW 5
#define COLUMN (ROW + 1)
static unsigned ix;
static unsigned iy;
static unsigned ctr = 1;
static unsigned sta = 0;
@byyam
byyam / config.ini
Created October 24, 2019 14:58
STUN demo
[server]
ip = 10.0.2.15
port = 11000
[client]
seq = 123456
@byyam
byyam / WRRS.py
Created October 24, 2019 14:45
WRRS
# define server map: {name : weight}
server_index = {0:'A', 1:'B', 2:'C'}
server_weight = {'A':4, 'B':3, 'C':2}
# global varibles
# server index is initialized with -1
# current weight is the current weight in scheduling, and current weight is initialized with 0
g_server_index = -1
g_current_weight = 0