Snippets


PHP:

	$p2c=polartoCartesian(36.8699,5);
	echo "p2c: angle=36.8699 distance=5 [$p2c[0]] [$p2c[1]]\n";

	$c2p=cartesiantoPolar(4,3);
	echo "c2p: x=4 y=3 [$c2p[0]] [$c2p[1]]\n";

function degreesToRadians($degrees)
{
	$radians=(pi()/180)*$degrees;
	return $radians;
}
function radiansToDegrees($radians)
{
	$degrees=$radians*(180/pi());
	return $degrees;
}
function polartoCartesian($deg,$radius)
{

	$radians=degreesToRadians($deg);

	$X= cos($radians) * $radius;
	$Y= sin($radians) * $radius;

	$retVal[0]=$X;
	$retVal[1]=$Y;


	return $retVal;
}
function cartesiantoPolar($x,$y)
{

	$C=sqrt( ($x*$x) + ($y*$y) );
	$angle=atan($x/$y);

	$angle=radiansToDegrees($angle);
	$angle=90-$angle; // to set 0deg at north;

	$retV[0]=$C;
	$retV[1]=$angle;

	return $retV;

}


function map($value, $fromLow, $fromHigh, $toLow, $toHigh) 
{
    $fromRange = $fromHigh - $fromLow;
    $toRange = $toHigh - $toLow;
    $scaleFactor = $toRange / $fromRange;
    $tmpValue = $value - $fromLow;
    $tmpValue *= $scaleFactor;
    return $tmpValue + $toLow;
}

bc – An arbitrary precision calculator language

Here is how to use bc to convert from one base to another.

bc -l

ibase=2;obase=A;1010001

81

Here the obase = A is in hex for 10.

 

Some times I like to have different versions of the Arduino IDE installed. I would also like them not to use the same preferences file and Sketchbook directory.

 

In the lib/preferences.txt file is hiddien this little piece of cryptic note:


# if you don't want settings to go into "application data" on windows
# and "library" on macosx, set this to the alternate location.
#settings.path=data

What that is trying to say… as it is not obvious. Is that if I want to store my preferences.txt file in a directory relative to the current IDE… uncomment that line.

This now allows me to keep all settings and sketchbooks relative to the IDE.

 

 

mapping in the bc calculator taken from Arduino 
bc -l An arbitrary precision calculator language
define map(x,in_min,in_max,out_min,out_max) { (x-in_min)*(out_max-out_min)/(in_max-in_min)+out_min }
use:
map(10,0,1024,5,15)
gives 5.097…

I always forget how to make a poster using ghostscript.

the command is ‘poster’

sample usage:

poster -v -mletter -c5% -s1 input.ps -o output.ps

This will enlarge the original and put crop marks on the resulting pages.

 

I created a LibreOffice cheat sheet to help me quickly learn and recall the syntax.

It covers some very useful things:

 

Getting the Sheet

Getting A Cell

Iterate over a range of cells:

Getting Form Elements
Set a Cell to current timestamp

HTTP Method GET call and store data
Reading And Writing A File

 

Trying out a new category: Snippets

These will be tiny shell scripts or pieces of code.

The first one is how to have linux convert GPS NMEA text files to kml format.

 

#!/bin/sh
gpsbabel -i NMEA -f $1 -o openoffice -F test.csv
gpsbabel -i openoffice -f ./test.csv -o kml -F test.kml

 

Im sure there is a better way…but this one works and gives a .csv file as an intermediate.