This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find array product like http://www.python.org/dev/peps/pep-0211/ | |
# which means | |
# [1,2,3]@[4,5]@[6,7] = [1,4,6],[1,4,7],[1,5,6],[1,5,7],[2,4,6]... and so on | |
def aprod(*arg): | |
numarg = len(arg) | |
lenarray = map(len,arg) | |
finallen = reduce(lambda x,y:x*y,lenarray) | |
divisor = map(lambda i: reduce(lambda x,y:x*y,lenarray[i+1:],1),xrange(numarg)) | |
index = [map(lambda n,l: (x/n)%l,divisor,lenarray) for x in xrange(finallen)] | |
#if you just want index for loop you can return index here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#py2cairo is notoriously broken under osx due to | |
#1) osx cairo version is too old | |
#2) waf is trying so hard to build a universal binary i386 and x86_64 and I found no way to override this | |
#replace Makefile in src/ with this one | |
#this will create _cairo.so | |
src = $(wildcard *.c) | |
#$(warning $(src)) | |
obj = $(patsubst %.c,%.o,${src}) | |
#$(warning $(obj)) | |
lib: ${obj} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t_flow = 3000.#m^3/s total chaopraya flow | |
t_area = 4000.#m^2 total crossection of chaopraya | |
rho = 1000.#kg/m^3 water density | |
#non interference | |
#P is power per boat (watts) | |
#A is effective area (m^3) | |
#n is number of boats | |
def flowdiff(P,A,n): | |
a_area = A #affected Area |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For faraway assumption | |
npara nseries totalnewflow | |
(1, 1000, 4174.006179381851) | |
(2, 500, 4174.008036625053) | |
(4, 250, 4174.011751293362) | |
(5, 200, 4174.013608718646) | |
(8, 125, 4174.019181358588) | |
(10, 100, 4174.022896755448) | |
(20, 50, 4174.04147738306) | |
(25, 40, 4174.05076997475) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstdarg> | |
#include <string> | |
//missing string printf | |
//this is safe and convenient but not exactly efficient | |
inline std::string format(const char* fmt, ...){ | |
int size = 512; | |
char* buffer = 0; | |
buffer = new char[size]; | |
va_list vl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================ | |
// gzstream, C++ iostream classes wrapping the zlib compression library. | |
// Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner | |
// | |
// This library is free software; you can redistribute it and/or | |
// modify it under the terms of the GNU Lesser General Public | |
// License as published by the Free Software Foundation; either | |
// version 2.1 of the License, or (at your option) any later version. | |
// | |
// This library is distributed in the hope that it will be useful, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <glob.h> | |
#include <vector> | |
#include <string> | |
inline std::vector<std::string> glob(const std::string& pat){ | |
using namespace std; | |
glob_t glob_result; | |
glob(pat.c_str(),GLOB_TILDE,NULL,&glob_result); | |
vector<string> ret; | |
for(unsigned int i=0;i<glob_result.gl_pathc;++i){ | |
ret.push_back(string(glob_result.gl_pathv[i])); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
//vector_inserter(idea taken from boost for those who don't wanna install boost) | |
//try vector<int> v; v+=1,2,3,4,5,6; | |
template <class T> class vector_inserter{ | |
public: | |
std::vector<T>& v; | |
vector_inserter(std::vector<T>& v):v(v){} | |
vector_inserter& operator,(const T& val){v.push_back(val);return *this;} | |
}; | |
template <class T> vector_inserter<T>& operator+=(std::vector<T>& v,const T& x){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <cstdarg> | |
//missing string printf | |
//this is safe and convenient but not exactly efficient | |
inline std::string format(const char* fmt, ...){ | |
int size = 512; | |
char* buffer = 0; | |
buffer = new char[size]; | |
va_list vl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef PODCACHE_H | |
#define PODCACHE_H | |
#include <tr1/unordered_map> | |
#include <cstring> | |
#include <limits.h> | |
#include <fstream> | |
#include <cassert> | |
#include <queue> | |
//simple serializable map for struct | |
template <class TK> class PODCache_bcmp{ |
OlderNewer