Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
peteristhegreat / 32bit color conversion 8bit color
Created February 26, 2015 19:58
Convert to and from 32 bit color to the Microsoft Safety Pallete (216) indexed colors.
// Generating a CLUT of the Microsoft Safety Pallete
// https://www.gidforums.com/t-21296.html
// Microsoft Safety Pallete
// https://msdn.microsoft.com/en-us/library/bb250466(VS.85).aspx
// Convert to indexed color
int index = (color.red()/51)*36
+ (color.green()/51)*6
+ color.blue()/51
+ 20;
@peteristhegreat
peteristhegreat / cpp_to_m.py
Created March 17, 2015 23:20
cpp to matlab converter using python and regular expressions (regex)
# Handles lots of cases but only for certain kinds of c++ coding
# Example conversion:
# int count = 0;
# for(int i = 0; i < 5; i++)
# count++;
#
# changes to
#
# count = 0;
@peteristhegreat
peteristhegreat / qt_wav_to_ogg_encoder_example.cpp
Last active August 10, 2021 17:36
Qt sample 16 bit Stereo Wav to Ogg Vorbis Encoder - Convert Wav to Ogg
/********************************************************************
* *
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
* by the Xiph.Org Foundation http://www.xiph.org/ *
* *
@peteristhegreat
peteristhegreat / Readme.md
Last active March 6, 2018 18:05
Using `PyQt` with `py2exe` example with runtime plugins, like icons

Start with miniconda installed. Use an IDE like PyCharm if you can.

Ensure conda is in the path

Create a PyCharm project Create a conda environment through PyCharm

Activate the new environment in a terminal (aka the command prompt)

@peteristhegreat
peteristhegreat / 3d-plot-dragzoom-persistent-inverted.m
Created August 19, 2015 22:01
Persistent pan, zoom, position in matlab in combination with the dragzoom tool.
% This uses http://www.mathworks.com/matlabcentral/fileexchange/29276-dragzoom-drag-and-zoom-tool
% and makes the last zoom of an open figure window persistent for the next run.
% These axis settings could get pushed to an external file to make them always happen, too.
% Place the following at the top of your .m file
% Store the position of figure 1
myfig = 0;
@peteristhegreat
peteristhegreat / fcn_RotationFromTwoVectors.m
Created August 20, 2015 22:09
Given two vectors, create a rotation matrix to rotate from A to B, in matlab
function R=fcn_RotationFromTwoVectors(A, B)
% http://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d
% R*v1=v2
% v1 and v2 should be column vectors and 3x1
%% Method 1
% % 1. rotation vector
% w=cross(v1,v2);
% w=w/norm(w);
% w_hat=fcn_GetSkew(w);
@peteristhegreat
peteristhegreat / projectPointsOntoPlane.m
Created August 25, 2015 21:20
Projects a point cloud in 3d space onto a plane defined by a normal unit vector and a point.
function P_project = projectPointsOntoPlane(uv, pointOnPlane, points)
% related: http://www.mathworks.com/matlabcentral/newsreader/view_thread/293244
% uv is a unit vector of the normal to the plane
% pointOnPlane is a point of the plane
% points is a point cloud that is to be projected (flattened) onto
% the plane
if(size(uv,1) == 3)
% one xyz point per column
Q = pointOnPlane';
m = size(points,2);
@peteristhegreat
peteristhegreat / Outlook Column Formula
Last active August 17, 2022 16:32
Relative Date Time in Outlook and Excel (minutes ago, hours ago, days ago), like Gmail
Go to:
Ribbon > View > View Settings > Columns... > New Column...
Name: "Ago"
Type: Formula
Formula:
IIF( Now() - [Received] <1/24, MINUTE( Now()-[Received] ) & " minutes ago",IIF( Now()-[Received] <1, HOUR( Now()-[Received] ) & " hours ago",IIF( Now()-[Received] <31, INT( Now()-[Received] ) & " days ago", "months ago")))
@peteristhegreat
peteristhegreat / unicode_cmds_vim.md
Last active October 28, 2022 01:11
Unicode commands vim

This isn't a file per se, but it is some secret vim-fu that lets you insert unicode and show it, and null characters:

First off in Vim if you see ^@ it is a NULL character. To type it, get into INSERT MODE and then press Ctrl-v, Ctrl-2.

Tada!

For entering in an html escaped unicode character, like the ones listed here:

http://www.amp-what.com/unicode/search/checkbox

@peteristhegreat
peteristhegreat / rgb_example.ino
Created April 5, 2016 01:58
RBG LED with button Arduino example, cycles colors 10x per second while the button is pressed
// https://learn.adafruit.com/adafruit-arduino-lesson-3-rgb-leds/breadboard-layout
// http://www.arduino.cc/en/Tutorial/Button
/*
Adafruit Arduino - Lesson 3. RGB LED
*/
int redPin = 11;
int greenPin = 10;