Skip to content

Instantly share code, notes, and snippets.

#/bin/bash
set -e
[ ${#@} -ne 2 ] && {
echo "Usage : $0 measurement_time(sec) bandwidth[|K|M](bps)"
echo "---"
echo "You also need to put 'hosts' file which contains target IPs."
exit 1
}
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void show(Mat *img){
cout << "Width " << img->cols << " / Height " << img->rows << endl;
imshow("Image", *img);
@nishidy
nishidy / stroll.py
Last active February 10, 2016 12:29
Nicer os.walk
import os,re
from functools import reduce
def stroll(topdir,no_root=[],yes_root=[],no_path=[],yes_path=[],no_file=[],yes_file=[],sortby=os.path.basename,reverse=False,ignorecase=True):
T=True
F=False
I=ignorecase
no_root.append("\..")
@nishidy
nishidy / stroll.cpp
Last active February 10, 2016 14:46
Nicer walk in C++
#include <iostream>
#include <algorithm>
#include <iterator>
#include <sys/stat.h>
#include <dirent.h>
#include <queue>
#include <regex>
namespace stroll {
@nishidy
nishidy / chart.py
Created February 10, 2016 16:01
Useful script to make chart
from collections import defaultdict
def init(data):
if isinstance(data, dict):
for key1, val1 in data.items():
if isinstance(val1, dict):
for key2, val2 in val1.items():
if isinstance(val2, dict):
for key3, val3 in val2.items():
@nishidy
nishidy / pandas_chart.py
Last active March 8, 2016 15:37
Python pandas chart test script
# coding: utf-8
import csv
import urllib3
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import pandas as pd
@nishidy
nishidy / ReflectionTest.java
Last active October 23, 2022 05:21
Java reflection/unsafe
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
import sun.misc.Unsafe;
class S {
private void privatePrintS () { System.out.println("This is in S."); };
public void publicPrintS () { System.out.println("This is in S."); };
}
@nishidy
nishidy / python_build.sh
Last active March 6, 2016 04:48
Python build
git clone https://github.com/python/cpython
cd cpython
git pull
export $(grep ^PACKAGE_VERSION= configure))
./configure --prefix=$HOME/.pyenv/versions/$PACKAGE_VERSION
make
make test
make install
ln -s $HOME/.pyenv/versions/$PACKAGE_VERSION/bin/python3 $HOME/.pyenv/versions/$PACKAGE_VERSION/bin/python
pyenv rehash
@nishidy
nishidy / pandas_dataframe_test.py
Last active March 9, 2016 17:02
Python pandas dataframes
import pandas as pd
import numpy as np
from collections import defaultdict
df1 = pd.DataFrame({"col1":[0,1,2,3],"col2":[4,5,6,7],"col3":[8,9,10,11]},index=["idx1","idx2","idx3","idx4"])
print("df1")
print(df1,end="\n\n")
df2 = pd.DataFrame([[0,4,8],[1,5,9],[2,6,10],[3,7,11]],index=["idx1","idx2","idx3","idx4"],columns=["col1","col2","col3"])
@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])