Skip to content

Instantly share code, notes, and snippets.

@ashelly
ashelly / mediator.c
Created May 28, 2013 20:36
Running Median. Finds the median of the last K inputs in O(lg K). See http://stackoverflow.com/q/5527437/10396 for some details.
//Copyright (c) 2011 ashelly.myopenid.com under <http://www.opensource.org/licenses/mit-license>
#include <stdlib.h>
//Customize for your data Item type
typedef int Item;
#define ItemLess(a,b) ((a)<(b))
#define ItemMean(a,b) (((a)+(b))/2)
typedef struct Mediator_t
// Put this in a separate .h file (called "getopt.h").
// The prototype for the header file is:
/*
#ifndef GETOPT_H
#define GETOPT_H
int getopt(int nargc, char * const nargv[], const char *ostr) ;
#endif
*/
@niw
niw / libpng_test.c
Last active January 14, 2025 21:59
How to read and write PNG file using libpng. Covers trivial method calls like png_set_filler.
/*
* A simple libpng example program
* http://zarb.org/~gc/html/libpng.html
*
* Modified by Yoshimasa Niwa to make it much simpler
* and support all defined color_type.
*
* To build, use the next instruction on OS X.
* $ brew install libpng
* $ clang -lz -lpng16 libpng_test.c
@aktau
aktau / stream-benchmark.c
Created September 15, 2013 14:46
Benchmark of writing to memory in C (clang and gcc), SSE stream vs SSE store vs naive...
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
/**
* compile and run:
*
* OSX:
import cv2
import numpy as np
def in_front_of_both_cameras(first_points, second_points, rot, trans):
# check if the point correspondences are in front of both images
rot_inv = rot
for first, second in zip(first_points, second_points):
first_z = np.dot(rot[0, :] - second[0]*rot[2, :], trans) / np.dot(rot[0, :] - second[0]*rot[2, :], second)
first_3d_point = np.array([first[0] * first_z, second[0] * first_z, first_z])
@TNick
TNick / test_blas.c
Last active February 12, 2019 15:33
Some routines to test blas and some code arround it
/*
* Author: Nicu Tofan
* License: BSD
*
* See below for getRealTime() license.
*/
#include <cblas.h>
@dinob0t
dinob0t / points_on_sphere
Last active February 24, 2023 16:37
Generates evenly distributed points on the surface of a sphere
"""
To generate 'num' points on a sphere of radius 'r' centred on the origin
- Random placement involves randomly chosen points for 'z' and 'phi'
- Regular placement involves chosing points such that there one point per d_area
References:
Deserno, 2004, How to generate equidistributed points on the surface of a sphere
http://www.cmu.edu/biolphys/deserno/pdf/sphere_equi.pdf
"""
@adolfo-rt
adolfo-rt / reem_self_collision
Created May 1, 2014 08:32
Self-collision avoidance trajectory generated by MoveIt! - trajectory_msgs::JointTrajectory part
header:
seq: 17
stamp:
secs: 1398930444
nsecs: 601168584
frame_id: ''
goal_id:
stamp:
secs: 1398930444
nsecs: 601169114
@rygorous
rygorous / u32_f32.c
Last active July 22, 2023 03:41
U32->F32 using SSE2 intrinsics.
// ---- Straightforward:
__m128i lo_int = _mm_and_si128(_mm_set1_epi32(0xffff), in); // low 16 bits of all vals
__m128i hi_int = _mm_srli_epi32(in, 16); // high 16 bits of all vals
__m128 lo_flt = _mm_cvtepi32_ps(lo_int); // exact (all 16 bit ints = machine numbers)
__m128 hi_flt = _mm_cvtepi32_ps(hi_int); // exact
__m128 hi_scl = _mm_mul_ps(hi_flt, _mm_set1_ps(65536.0f)); // exact (just exponent change)
__m128 result = _mm_add_ps(hi_scl, lo_flt); // this is the only step that rounds.
// same approach also works with FMA where available.
@leftclickben
leftclickben / gist:322b7a3042cbe97ed2af
Last active June 7, 2023 10:58
Steps to migrate from SVN to GitLab

Steps to migrate from SVN to GitLab

This process worked for me. I take no responsibility for any damage or loss incurred as a result of following or not following these steps or, for that matter, anything else you might do or not do.

Setup

  • SVN is hosted at svn.domain.com.au.
  • SVN is accessible via http (other protocols should work).
  • GitLab is hosted at git.domain.com.au and: