Skip to content

Instantly share code, notes, and snippets.

View ruofeidu's full-sized avatar

Ruofei Du ruofeidu

View GitHub Profile
@ruofeidu
ruofeidu / mnist.h
Last active November 28, 2017 02:48
MNIST C++ IO Helper Header
#pragma once
#include <string>
#include <opencv/cv.hpp>
using namespace cv;
using namespace std;
uchar** read_mnist_images(string full_path, int& number_of_images, int& image_size) {
auto reverseInt = [](int i) {
unsigned char c1, c2, c3, c4;
c1 = i & 255, c2 = (i >> 8) & 255, c3 = (i >> 16) & 255, c4 = (i >> 24) & 255;
return ((int)c1 << 24) + ((int)c2 << 16) + ((int)c3 << 8) + c4;
@ruofeidu
ruofeidu / PhotoViewer.reg
Created October 12, 2017 15:24
Enable Windows Photo Viewer in Windows 10
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Applications\photoviewer.dll]
[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell]
[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open]
"MuiVerb"="@photoviewer.dll,-3043"
[HKEY_CLASSES_ROOT\Applications\photoviewer.dll\shell\open\command]
@ruofeidu
ruofeidu / CudaHelper.h
Last active August 22, 2018 17:37
CUDA Helper for Visual Studio INTELLISENSE
#pragma once
#pragma comment(lib, "cudart.lib")
#if _DEBUG
#pragma comment(lib, "opencv_world330d.lib")
#else
#pragma comment(lib, "opencv_world330.lib")
#endif
#ifdef __CUDACC__
@ruofeidu
ruofeidu / sample.py
Last active November 28, 2017 02:47
Weighted Random Generator
import itertools, random, bisect
class WeightedRandomGenerator(object):
def __init__(self, weights):
self.totals = []
running_total = 0
for obj in weights:
running_total += weights[obj]
@ruofeidu
ruofeidu / rename.py
Created December 13, 2017 16:16
Batch renaming files under this script's folder
# -*- coding: utf-8 -*-
# This script renames all files under this script's folder
# Ruofei Du
# 12/13/2017
import glob, os
prefix = 'bing_'
dir_path = os.path.dirname(os.path.realpath(__file__))
sub_dir_list = glob.glob(dir_path + '*')
for dir_item in sub_dir_list:
import glob, os
dir_path = os.path.dirname(os.path.realpath(__file__))
print(dir_path)
sub_dir_list = glob.glob(dir_path + '\\test2\\*')
for dir_item in sub_dir_list:
print(dir_item)
sub_list = glob.glob(dir_item + '\\*')
for item in sub_list:
l = glob.glob(item + "\\*")
@ruofeidu
ruofeidu / php5.ini
Created February 22, 2018 21:28
Setup PHP varialbes for debugging purpose
cgi.fix_pathinfo=0
file_uploads = On
post_max_size = 500M
upload_max_filesize = 500M
memory_limit = 256M
@ruofeidu
ruofeidu / bilinear_get_color.py
Created April 10, 2018 17:29
Obtain color with bilinear filtering on the CPU, equivalent to the default bilinear filtering on the GPU
# type: (list, float, float) -> list
# img: the input image
# cx, cy: image coordinates in floats
def bilinear_get_color(img, cx, cy):
x, y = [int(floor(cx)), int(ceil(cx))], [int(floor(cy)), int(ceil(cy))]
u, v = cx - x[0], cy - y[0]
r = np.zeros((2, 2, 3), np.uint8)
w, h = len(img[0]), len(img)
for i in range(2):
for j in range(2):
@ruofeidu
ruofeidu / taiwanip.php
Created May 24, 2018 18:00
Test if the IP address comes from Taiwan haha
/**
* @desc 判断ip是否为台湾IP
* @param string $ip 字符串格式的ip
* @return boolean 是台湾IP的话返回true,否则返回false
*/
public static function isTaiwanIp($ip) {
$longip = sprintf("%u", ip2long($ip));
switch ($longip % 100000000) {
case 0:
if (($longip>=19005440 AND $longip<=19136511)
@ruofeidu
ruofeidu / trie.py
Last active July 12, 2018 18:58 — forked from crlane/trie.py
An implementation of a trie in python using defaultdict and recursion
from collections import defaultdict
def node():
return defaultdict(node)
def word_exists(word, node):
if not word:
return None in node
return word_exists(word[1:], node[word[0])