Skip to content

Instantly share code, notes, and snippets.

nishidy

Block or report user

Report or block nishidy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nishidy
nishidy / client.py
Last active Apr 29, 2019
TCP KEEPALIVE and TIME_WAIT
View client.py
import socket
import time
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('xxxxxxxx', 8080))
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
s.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 35)
s.send(b'GET / HTTP/1.1\r\nHost: localhost')
data = s.recv(1024)
print(data)
@nishidy
nishidy / client.py
Last active Apr 2, 2019
TCP_DEFER_ACCEPT test program for client (python)
View client.py
import socket
import time
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('127.0.0.1', 8080))
time.sleep(1)
s.send(b'GET / HTTP/1.1\r\nHost: localhost')
data = s.recv(1024)
print(data)
@nishidy
nishidy / server.py
Last active Apr 29, 2019
TCP_DEFER_ACCEPT test program for server (python)
View server.py
import socket
QUEUELIMIT = 5
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('',8080))
s.listen(QUEUELIMIT)
s.setsockopt(socket.SOL_TCP, socket.TCP_DEFER_ACCEPT, 1)
while True:
conn, addr = s.accept()
@nishidy
nishidy / client.c
Last active Apr 2, 2019
TCP_DEFER_ACCEPT test program for client
View client.c
#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 Apr 2, 2019
TCP_DEFER_ACCEPT test program for server
View server.c
#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 / cs.sh
Last active Aug 18, 2017
Convenient Search command
View cs.sh
#!/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 / amazon_api_test.py
Last active Jun 18, 2017
Amazon Product API
View amazon_api_test.py
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
Find common list in three lists
View find_common.py
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
Consistent Hashing in C++
View consistent_hashing.cpp
#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 / quick_sort.py
Created May 2, 2017
Quick Sort in Python
View quick_sort.py
class Sorter:
def __init__(self,data):
self.orig = data.copy()
self.data = data
def do_qsort(self):
print("Original data",self.orig)
self.run_qsort(0,len(self.data)-1)
print("Sorted data ",self.data)
You can’t perform that action at this time.