Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
insaneyilin / USACO_1_1_1_ride.cpp
Created July 10, 2015 06:54
My USACO solutions
/*
ID: yilin.g1
PROG: ride
LANG: C++
*/
/*
Your Ride Is Here
http://train.usaco.org/usacoprob2?a=1riZcYaDeJF&S=ride
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
void color_reduce1(const cv::Mat& src_mat, int div, cv::Mat* dst_mat) {
@insaneyilin
insaneyilin / erase_elems_by_indices.cpp
Created June 26, 2018 06:18
C++ Erase elements from containers by indices
// https://coderwall.com/p/jsxrdq/c-erase-elements-from-containers-by-indices
template<typename Cont, typename It>
auto ToggleIndices(Cont &cont, It beg, It end) -> decltype(std::end(cont))
{
int helpIndx(0);
return std::stable_partition(std::begin(cont), std::end(cont),
[&](decltype(*std::begin(cont)) const& val) -> bool {
return std::find(beg, end, helpIndx++) == end;
});
# from https://github.com/BVLC/caffe/blob/master/examples/detection.ipynb
def nms_detections(dets, overlap=0.3):
"""
Non-maximum suppression: Greedily select high-scoring detections and
skip detections that are significantly covered by a previously
selected detection.
This version is translated from Matlab code by Tomasz Malisiewicz,
who sped up Pedro Felzenszwalb's code.
@insaneyilin
insaneyilin / progress_bar.py
Created August 16, 2018 12:01
simple python progress bar
def progress(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '>' + '-' * (bar_len - filled_len)
if count < total:
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
else:
@insaneyilin
insaneyilin / compress_image.py
Created July 1, 2019 17:41
compress image with file size threshold
# -*- coding: utf-8 -*-
# @Author: insaneyilin
# Python version 2.7
# Reference: https://www.cnblogs.com/li1992/p/10675769.html
import os
import sys
import argparse
import glob
@insaneyilin
insaneyilin / shared_object_pool.h
Created July 10, 2019 12:58
A simple object pool. (not thread-safe, return std::shared_ptr)
#ifndef IG_SHARED_OBJECT_POOL_H_
#define IG_SHARED_OBJECT_POOL_H_
#include <cstdlib>
#include <queue>
#include <vector>
#include <list>
#include <memory>
namespace ig {
@insaneyilin
insaneyilin / cpp_cmp_struct_using_tie.cpp
Created August 7, 2019 10:51
compare struct using std::tie()
struct Student {
int stu_id;
int age;
float grade;
};
std::vector<Student> students;
// fill students vector
// ...
@insaneyilin
insaneyilin / newton_sqrt.scm
Created August 12, 2019 16:24
Find square-root using Newton method in Scheme
(define (average x y)
(* (+ x y) 0.5))
(define (good_enough? guess x)
(< (abs (- x (* guess guess))) 0.001))
(define (improve guess x)
(average guess (/ x guess)))
(define (sqrt_itr guess x)
@insaneyilin
insaneyilin / register_factory.cpp
Last active October 7, 2019 16:22
C++ class register factory
// Copyright (c) 2019 Yilin Gui. All rights reserved.
//
// filename: register_factory.cpp
#include "./register_factory.h"
namespace register_factory {
BaseClassFactoryMap& GlobalBaseClassFactoryMap() {
static BaseClassFactoryMap base_factory_map;