Skip to content

Instantly share code, notes, and snippets.

View typhoonzero's full-sized avatar

Wu Yi typhoonzero

  • Beijing
View GitHub Profile
@typhoonzero
typhoonzero / Singleton.hpp
Created December 27, 2016 11:23
A thread safe base template class of c++ Singleton
#include <stdlib.h>
#include <iostream>
#include <pthread.h>
#ifndef SINGLETON_H
#define SINGLETON_H
namespace util {
template <class T>
class Singleton {
@typhoonzero
typhoonzero / isavl.cpp
Created December 27, 2016 11:25
Check if a binary tree is AVL tree
#include <iostream>
#include <stack>
#include <stdlib.h>
struct BTree {
int value;
int depth;
BTree *left;
BTree *right;
};
@typhoonzero
typhoonzero / exp_template.py
Created June 15, 2017 06:21
Expression Template in python
import numpy as np
class Any():
def __init__(self):
pass
class Vec(Any):
def __init__(self, vec):
self._vec = vec
def __getitem__(self, idx):
@typhoonzero
typhoonzero / dict_to_proto.py
Last active August 11, 2017 02:09
parse python dict to protobuf message
def parse_list(values, message):
if isinstance(values[0], dict):
for v in values:
cmd = message.add()
parse_dict(v, cmd)
else:
message.extend(values)
def parse_dict(values, message):
for k, v in values.iteritems():
@typhoonzero
typhoonzero / functor_template.h
Last active January 2, 2018 03:55
C++ expression template example for mixing sparse (indices) and dense vector
#include <iostream>
#include <vector>
#include <set>
#include <initializer_list>
template<typename E>
struct ExpressionFunctor {
double operator[](size_t i) const { return static_cast<E const&>(*this)[i]; }
size_t size() const { return static_cast<E const&>(*this).size(); }
@typhoonzero
typhoonzero / paddle_on_ray.py
Created January 15, 2018 11:11
Run PaddlePaddle on ray
import ray
import paddle.v2 as paddle
import paddle.v2.fluid as fluid
import numpy
ray.init()
NUM_WORKERS = 2
BATCH_SIZE = 128
@typhoonzero
typhoonzero / fluid_local_dist_debug.sh
Last active June 4, 2018 09:12
Debug fluid distributed jobs on local machine.
#!/bin/bash
PSERVERS=""
for i in {6170..6171}
do
if [ "${PSERVERS}" == "" ]; then
PSERVERS="127.0.0.1:${i}"
else
PSERVERS="${PSERVERS},127.0.0.1:${i}"
fi
@typhoonzero
typhoonzero / rpc_server.h
Last active May 29, 2018 03:10
An example of how to abstract fluid rpc server
#include <string>
#include <condition>
#include <atomic>
class RPCServer;
/*
* Handler Class for the server to use
*/
class RequestHandler {
public:
@typhoonzero
typhoonzero / check_ctest_hung_test.py
Created June 12, 2018 09:24
get which ctest case hungs from the ctest log
import sys
import re
def escape(input):
o = input.replace("\n", "")
o = o.replace("\r", "")
return o
def main():
logfile = sys.argv[1]
#!/bin/bash
image="paddlepaddle/paddle"
tags=`wget -q https://registry.hub.docker.com/v1/repositories/${image}/tags -O - | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n' | awk -F: '{print $3}'`
if [ -n "$2" ]
then
tags=` echo "${tags}" | grep "$2" `
fi