Skip to content

Instantly share code, notes, and snippets.

@byyam
byyam / printer.cpp
Created May 26, 2015 11:57
print a graph
// NOTE: compile with g++ filename.cpp -std=c++11
#include <stdio.h>
#include <cmath>
#include <cstdlib>
#include <time.h>
#define DIM 1024
#define DM1 (DIM-1)
#define _sq(x) ((x)*(x)) // square
#define _cb(x) abs((x)*(x)*(x)) // absolute value of cube
@byyam
byyam / gin-json-schema.go
Last active September 6, 2021 11:28
gin json schema
package main
import (
"fmt"
"bytes"
"strings"
"io/ioutil"
"net/http"
"github.com/gin-gonic/gin"
"github.com/xeipuuv/gojsonschema"
)
@byyam
byyam / interface-reflect.go
Created August 12, 2019 10:25
interface compare nil
package main
import (
"fmt"
"reflect"
)
type State struct{}
func testnil1(a, b interface{}) bool {
@byyam
byyam / memory-cache.go
Last active October 24, 2019 15:01
cache in memory
package main
import (
"fmt"
"sync"
"time"
"runtime"
)
type keyAndValue struct {

Keybase proof

I hereby claim:

  • I am byyam on github.
  • I am yamzzz (https://keybase.io/yamzzz) on keybase.
  • I have a public key ASASe_RhGfvyDxjLcBTJF_B0nKpx1vEwZ8ToJq9N5pKIlAo

To claim this, I am signing this object:

@byyam
byyam / collatz_conjecture.cpp
Created October 24, 2019 14:38
collatz conjecture
#include <stdio.h>
#include <limits.h>
const int s = 30;
bool f(long i)
{
int r = 0;
for(;;)
if (i < 0 || r > s) return false;
else if (i == 1) break;
@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
@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 / 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 / __init__.py
Created October 24, 2019 15:04
mysql py
#####