Skip to content

Instantly share code, notes, and snippets.

@nishidy
nishidy / client.c
Last active April 2, 2019 17:13
TCP_DEFER_ACCEPT test program for client
#include <stdio.h> //printf(), fprintf(), perror()
#include <sys/socket.h> //socket(), connect(), recv()
#include <arpa/inet.h> // struct sockaddr_in, struct sockaddr, inet_ntoa(), inet_aton()
#include <stdlib.h> //atoi(), exit(), EXIT_FAILURE, EXIT_SUCCESS
#include <string.h> //memset()
#include <unistd.h> //close(), sleep()
#include <linux/tcp.h> //TCP_DEFER_ACCEPT
#define MSGSIZE 32
#define MAX_MSGSIZE 1024
@nishidy
nishidy / server.c
Created April 2, 2019 15:18
TCP_DEFER_ACCEPT test program for server
#include <stdio.h> //printf(), fprintf(), perror()
#include <sys/socket.h> //socket(), connect(), recv()
#include <arpa/inet.h> // struct sockaddr_in, struct sockaddr, inet_ntoa(), inet_aton()
#include <stdlib.h> //atoi(), exit(), EXIT_FAILURE, EXIT_SUCCESS
#include <string.h> //memset()
#include <unistd.h> //close()
#include <linux/tcp.h> //TCP_DEFER_ACCEPT
#include <time.h> //
#define MSGSIZE 32
@nishidy
nishidy / random_memoranda.md
Last active October 13, 2017 14:04
Random memoranda

vmstat

$ vmstat -n 2 | perl -e 'while(<>){print localtime().": $_"}'
Fri Dec 30 15:34:51 2016: procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
Fri Dec 30 15:34:51 2016:  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
Fri Dec 30 15:34:51 2016:  2  0  57216  94916  93012 135552    4   22   601    39  216  593  2  2 94  2
Fri Dec 30 15:34:53 2016:  0  0  57216  94296  93012 135552    0    0     0     0  201  737  1  1 98  0
Fri Dec 30 15:34:55 2016:  0  0  57216  94296  93012 135552    0    0     0     0  176  707  1  1 98  0
Fri Dec 30 15:34:57 2016:  0  0  57216  94296  93012 135552    0    0     0     0  174  656  1  1 98  0
@nishidy
nishidy / cs.sh
Last active August 18, 2017 01:19
Convenient Search command
#!/bin/bash
if [ -z "$*" ]; then
echo "cs [OPTIONS] DIR"
echo " ORDER BY OPTIONS:"
echo " -f : file count"
echo " -s : file size"
echo " -m : file modification time"
echo " -j : total size of files just under a directory"
echo " -a : total size of files all under a directory"
@nishidy
nishidy / mp.py
Last active July 9, 2017 07:46
TensorFlow Multilayer Perceptron (2 hidden layers with 100 nodes respectively)
from tensorflow.examples.tutorials.mnist import input_data
# one_hot is for multiclass classification
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
import tensorflow as tf
# Input
# 784 = 28 x 28
# Mini batch size is not fixed here
x = tf.placeholder(tf.float32, [None,784])
@nishidy
nishidy / amazon_api_test.py
Last active June 18, 2017 13:48
Amazon Product API
import os
import time
from amazon.api import AmazonAPI
AMAZON_ACCESS_KEY = os.environ['AWSAccessKeyId']
AMAZON_SECRET_KEY = os.environ['AWSSecretKey']
AMAZON_ASSOC_TAG = os.environ['AWSAssocId']
print(AMAZON_ACCESS_KEY[-5:])
print(AMAZON_SECRET_KEY[-5:])
@nishidy
nishidy / find_common.py
Last active May 15, 2017 12:52
Find common list in three lists
from random import random
import time
import sys
def findCommon_NNN(A,B,C):
if 1000<len(A) or 1000<len(B) or 1000<len(C):
print("# This may be huge input for this function with O(N^3). Exit.")
return []
@nishidy
nishidy / consistent_hashing.cpp
Last active May 7, 2017 15:30
Consistent Hashing in C++
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
//#include <list> # lower_bound does not work
#include <openssl/sha.h>
#include <assert.h>
@nishidy
nishidy / merge_sort.py
Last active May 2, 2017 23:26
Merge Sort in Python
class Sorter:
def __init__(self,data):
self.data = data
def do_msort(self):
print("Original data",self.data)
self.run_msort(0,len(self.data)-1)
print("Sorted data ",self.data)
def run_msort(self,i,j):
@nishidy
nishidy / lcs.py
Last active April 23, 2017 13:45
Longest Common Subsequence
class LCD:
def __init__(self,s1,s2):
self.s1 = s1
self.s2 = s2
print(s1,s2)
def solve(self):
a = [ [ 0 for y in range(len(self.s2)+1) ] for x in range(len(self.s1)+1) ]
for x in range(len(self.s1)):
for y in range(len(self.s2)):