Skip to content

Instantly share code, notes, and snippets.

@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 / 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
#/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
}
@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 / 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 / a.hs
Created May 6, 2016 13:31
Google Code Jam 2016 Qualification Round : Problem A. Counting Sheep
import Data.List
import Debug.Trace
import Control.Applicative
testloop :: Integer -> Integer -> IO String
testloop n t | n>t = return ""
testloop n t = getLine >>= teststr >>= \x->return ("Case #"++(show n)++": "++x) >>= putStrLn >> testloop (n+1) t
teststr :: String -> IO String
teststr s = disp $ dropWhile check0to9 $ concatnums $ numlist 1 s
@nishidy
nishidy / b.hs
Created May 6, 2016 13:32
Google Code Jam 2016 Qualification Round : Problem B. Revenge of the Pancakes
import Debug.Trace
testloop :: Integer -> Integer -> IO String
testloop i t | i>t = return ""
testloop i t = getLine >>= testnum 0 >>= \x->return ("Case #"++(show i)++": "++x) >>= putStrLn >> testloop (i+1) t
testnum :: Integer -> String -> IO String
--testnum n s = flipcakes s >>= \x-> trace(x) (oneside n x)
testnum n s = case oneside n s of
Just n | any (=='+') s == True -> return $ show n
@nishidy
nishidy / c.hs
Created May 6, 2016 13:33
Google Code Jam 2016 Qualification Round : Problem C. Coin Jam (Only for small)
import Data.Char
import GHC.Float
import Debug.Trace
testloop :: Int -> Int -> IO ()
testloop i t | i>t = return ()
--testloop i t = getLine >>= \x-> trace(x) (lineloop x)
testloop i t = getLine >>= lineloop >>= \x-> putStrLn ("Case #"++(show i)++":\n"++x) >> testloop (i+1) t
lineloop :: String -> IO String