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
*/
@insaneyilin
insaneyilin / show_opencv_image_in_opengl.cpp
Last active November 20, 2023 05:47
Show opencv cv::Mat image in an OpenGL window(use GLFW)
/*
# Released under MIT License
Copyright (c) 2017 insaneyilin.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@insaneyilin
insaneyilin / opengl_mult_viewports_example.cpp
Created July 1, 2017 14:46
OpenGL multiple viewports example
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
static int width;
static int height;
static void display(void) {
#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
// ...