Skip to content

Instantly share code, notes, and snippets.

@cwyang
cwyang / ssltest.py
Created Jun 8, 2021
ssl teardown test
View ssltest.py
import socket, ssl, sys
if len(sys.argv) == 1:
hostname = 'www.naver.com'
else:
hostname = sys.argv[1]
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
View monif.py
import os
import socket
import struct
# These constants map to constants in the Linux kernel. This is a crappy
# way to get at them, but it'll do for now.
RTMGRP_LINK = 1
NLMSG_NOOP = 1
NLMSG_ERROR = 2
View vpp_api_test.py
#!/usr/bin/env python3
import os
import time
import fnmatch
from vpp_papi import VPPApiClient
def init_vpp(vpp_json_dir='/usr/share/vpp/api/core/'):
jsonfiles = []
@cwyang
cwyang / ssl_keepalive.py
Last active Feb 16, 2021
open SSL connection with TCP keepalive
View ssl_keepalive.py
import socket
import ssl
def set_keepalive_linux(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
"""Set TCP keepalive on an open socket.
It activates after 1 second (after_idle_sec) of idleness,
then sends a keepalive ping once every 3 seconds (interval_sec),
and closes the connection after 5 failed ping (max_fails), or 15 seconds
"""
View gist:23220d7fed5a0cc9af21949aad70e2f6
#!/usr/bin/perl
#
# 21 Apr 2020
# Chul-Woong Yang
#
# Client (C) Proxy (P1) Proxy (P2)
# 10.10.1.1/24 10.10.2.1/24 10.10.3.1/24
# veth0 veth0 veth0
# | | |
# veth pair veth pair veth pair
@cwyang
cwyang / regression_keras.py
Last active Dec 18, 2018
polynomial regression try with keras
View regression_keras.py
%matplotlib inline
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import Adam
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#Generate data
num_data=10000
@cwyang
cwyang / graph.hs
Created Nov 1, 2016
an implementation of shortest path
View graph.hs
import Data.Array
import Data.Array.ST
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Monad.ST
import Data.Maybe
import Control.Applicative
import Debug.Trace
type Vertex = Int