Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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;
@peteristhegreat
peteristhegreat / PieChart.qml
Last active July 29, 2016 03:38
qt-quick-qml-and-canvas-tutorial pie chart example
// http://www.slideshare.net/emayssat/qt-quick-qml-and-canvas-tutorial
import QtQuick 2.0
Item {
Rectangle {
id: root
width: 640
height: 360
color: "#3C3C3C"
ListModel {
@peteristhegreat
peteristhegreat / explode_rows.vba
Last active August 30, 2016 20:54
Excel explode rows split rows based on a column vba script
Sub Main()
Call explode_rows("Sheet1", "Sheet2", 2, ",")
End Sub
Function explode_rows(sheet_src As String, sheet_dest As String, col As Integer, sep As String)
Dim wb As Workbook
Dim r_src As Integer
Dim r_dest As Integer
@peteristhegreat
peteristhegreat / bash_stack_trace.bash
Created November 7, 2016 19:19
Show a back trace in bash with context lines.
# Prints the stack trace and some context lines for where the stack trace happened
# rotate the log
unlink /var/rotating_log.log
datetime=$(date +%m%d%Y_%H%M%S);
logfile="rotating_log_$datetime.log"
echo "Started on $datetime" > $logfile
#chfile mygroup 664 $logfile
ln -s $logfile rotating_log.log
@peteristhegreat
peteristhegreat / sample_d4m.json
Created January 4, 2017 03:55
sample json for decide4me
{
"game_setups": [
{
"name": "setup_template",
"players": [
{
"name": "Player 1"
},
{
"name": "Player 2"
@peteristhegreat
peteristhegreat / readonlydelegate.cpp
Created January 17, 2017 20:59
Read-only QItemDelegate for use with Qt QTableView
#include "readonlydelegate.h"
ReadOnlyDelegate::ReadOnlyDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
bool ReadOnlyDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
return false;