Skip to content

Instantly share code, notes, and snippets.

@cwyang
cwyang / graph.hs
Created November 1, 2016 09:24
an implementation of shortest path
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
@cwyang
cwyang / regression_keras.py
Last active December 18, 2018 21:55
polynomial regression try with keras
%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
img
#!/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 / ssl_keepalive.py
Last active February 16, 2021 02:07
open SSL connection with TCP keepalive
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
"""
#!/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 = []
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
@cwyang
cwyang / ssltest.py
Created June 8, 2021 12:03
ssl teardown test
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
@cwyang
cwyang / test_packet.py
Created May 26, 2022 13:58
os-ken & logger perf
import sys
import logging
from os_ken.ofproto import ether, inet
from os_ken.lib.packet import ethernet
from os_ken.lib.packet import ipv4, ipv6
from os_ken.lib.packet import tcp, udp
from os_ken.lib.packet import packet, packet_utils
from os_ken.lib import addrconv
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "bento/ubuntu-22.04"
config.vm.box_check_update = false
vmcpu=(ENV['VPP_VAGRANT_VMCPU'] || 8)
vmram=(ENV['VPP_VAGRANT_VMRAM'] || 12192)