Skip to content

Instantly share code, notes, and snippets.

View blackball's full-sized avatar
🎯
Focusing

Hui blackball

🎯
Focusing
View GitHub Profile
/// For modules that we care about the memory safety, we should never allow user
/// to have a way to access the memory directly. In this case, handle will be a
/// more useful tool. But in order to use handle safely, some tricks required.
/// Here I try to make an example of using handle to design simple API.
/// NOTE: for now we assume all codes will only be ran in single-thread, MT
// could be enabled easily though.
#include <stdio.h>
#include <stdlib.h>
@blackball
blackball / Sample_On_Sphere.py
Created June 29, 2018 12:03
Two methods sampling on a sphere:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# http://marc-b-reynolds.github.io/math/2018/06/21/SFPoints4ET.html
import numpy as np
"""
// constant turning rate:
// TX = cos(2pi K)
import matplotlib.pyplot as plt
import cv2
import numpy as np
def GetNeighbors(r, c, A, B, C):
# 1 2 3
# 4 5 6
# 7 8 9
n = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]
neighbors = []
#include "paraknn.h"
#define SIFTDIM 128
// need AVX2 + FMA, compiler options: -march=native -O3
static inline float
_Distance2_SIFT128(const float *va, const float *vb) {
__m256 zmm= _mm256_set1_ps(0.f), amm, bmm;
@blackball
blackball / download-full-circle.py
Created November 25, 2014 14:37
Download full circle magazines
# Download full circle magazines.
# This script are copied from some where else.
from os.path import basename
from urlparse import urlsplit
import urllib2
def url2name(url):
return basename(urlsplit(url)[2])
@blackball
blackball / aligned-mem.c
Last active August 29, 2015 14:05
simple binary feature with robust probabilistic algorithm could be very effective.
#include "aligned-mem.h"
#include <stdlib.h>
void *
aligned_malloc(size_t sz, size_t align) {
if (align & (align-1))
return 0;
void *m = malloc(sz + align + sizeof(void *));
void **p = (void **)((size_t)(m + align + sizeof(void*)) & ~(align-1));
// Codes to show the 'uniform pattern' of LBP
#include <stdio.h>
typedef unsigned char uint8_t;
#define BIT_AT(v, pos) (((v) >> (pos)) & 1)
static int
numOfTran(uint8_t v) {
@blackball
blackball / mheap.h
Last active August 29, 2015 14:04
simply implement min heap, there's a faster version in repo "boring", but not very conveniant when prototyping
/**
* Implement a min binary heap class for scalar type.
*/
#ifndef MHEAP_H
#define MHEAP_H
#include <vector>
#include <assert.h>
@blackball
blackball / pipe_cmd.py
Created July 26, 2014 07:41
Lazy pipe executable task in python, wrote in ~3 years ago.
#!/usr/bin/python
"""
Simulate a command pipe in windows.
reason: I always need to do batch processing
in my dailylife, rename a bunch of files,
generate some sets from it, and move files
into different folders. Or, I have a module,
and I need to processing lots of file, but,
this module can only process one at most, and I
@blackball
blackball / cap.h
Last active August 29, 2015 14:04
A simple warpper for Capture in C++.
/**
* A simple warpper for Capture in C++.
*
* @blackball
*/
#ifndef OPENCV_CAP_H
#define OPENCV_CAP_H
#include <opencv/cv.h>