Posts tagged ‘Reference’

ISO Date/Time in java

took me a while to figure this one out, you’d think getting a standarized date/time would be a bit simpler…

put the following in a class

private final static SimpleDateFormat dateFormat;
static {
    //as per ISO 8601
    dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    //make sure the formatter requires an exact string
    dateFormat.setLenient(false);
    //set "timezone" to Universal Time Coordinates (GMT adjusted by leap seconds)
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}

and the following elsewhere in the class:

//to create a string
String nowString = dateFormat.format(new Date());
//to parse a proper string to a date
Date nowDate = dateFormat.parse(nowString);

concatenate (join together) several *.pdf files

pdf is a document format. there are occasions where I find it easier to work with one large document rather than several single documents (most recently, while working with several spec sheets for electronic components), the following command will join two or more *.pdfs into a single document using ghostscript.

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=OUTPUT.pdf INPUT01.pdf INPUT02.pdf ...

-dBATCH - exit after last file
-dNOPAUSE - no pause after page
-q - “quiet”, fewer messages
-sDEVICE=<devname> - select device, in this case the pdf writer
-sOutputFile=<file> - select output file

the following were not, but could be, included:
-g<width>x<height> - page size in pixels
-r<res> - pixels/inch resolution

Pointers and References

declaring the variables:

	int A;
	int *pA;
	int B;
	int *pB;

at this point, A is a container for an integer, and B is a container for a pointer to an integer.

in the body of the code, a “*” can be seen as “the value pointed to by”, and “&” can be seen as “the address of”, as in (using the above delarations):

	A = 100; //directly sets the value of A
	pA = &A; //now pA contains the address of A
	pB = pA; //now pB contains the value of pA, which is the address of A
	B = *pB; //now B contains the value that is pointed to by pB

now both A and Bcontain “100″, and both pA and pB contain the location of A.

 

	cout << "A:  " << A << endl;    //displays value in A
	cout << "B:  " << B << endl;    //displays value in B
	cout << "pA: " << pA << endl;   //displays address in pA
	cout << "pB: " << pB << endl;   //displays address in pB
	cout << "*pA: " << *pA << endl; //displays value pointed to by pA
	cout << "*pB: " << *pB << endl; //displays value pointed to by pB
	cout << endl;

would show something like the following (note that [ADDRESS] would actually be a memory location):

A:  100
B:  100
pA: 0x[ADDRESS]
pB: 0x[ADDRESS]
*pA: 100
*pB: 100

 
at this point, setting the value held by A could be done in any of the following ways:

	A = 200;
	*pA = 200;
	*pB = 200;

*pB can be used to set the value of A because pB contains the address of A.

note that B contains the same value as is in A, but is now independant of it. in the above example, A was set, then pA was set to it’s address, then pB was set to the contents of pA, then B was set the the value pointed to by pB.

converting *.pdf to an image series

pdf is a document format. on the occasion where it is easier to reference an image rather than the full document, the following command will convert the pdf.

convert -density 96x96 -trim INPUTFILE.pdf OUTPUTFILE.jpg

-density is the image density in pixels per square inch
-trim will trim the image edges

the output will be in the form of OUTPUTFILE-#.jpg, where # is an increasing “page” number.
this command will also work for OUTPUTFILE.png, OUTPUTFILE.gif, et. al..

also, imagemagick uses ghostscript to convert, so the quality of the final images will only be as good as ghostscript can provide.

Converting *.flac to *.mp3

flac is an audio format (Free Lossless Audio Codec) that is excellent for archiving, but few if any portable players will be able to play it, so a method to convert to mp3 is shown below.

convert .flac to .mp3

flac -cd "FILENAME.flac" | lame -h - "FILENAME.mp3"

flac: -c is output to console, -d is decode
lame: -h is shorthand for “-q 2″ and -q is quality (in this case a high quality), “-” is input from console

same but for all .flac files in a directory

for FILE in *.flac; do $(flac -cd "$FILE" | lame -h - "${FILE%.flac}.mp3"); done

same options in a bash for loop, the ${FILE%.flac} strips “.flac” from the name

Notes:
id3 options for lame:
–tt <title> –ta <artist> –tl <album> –ty <year> –tc <comment> –tn <track> –tg <genre>
will automatically add an id3v1 or id3v2 as needed (choice is based on the size of the fields),
“–add-id3v2″ “–id3v2-only” “–id3v1-only” can be used to modify choice.

more complicated operations are beyond the scope of this article, but I’d suggest using K3B.

AVR Toolchain - Build 2008-04-15 - Man Pages

Every version of UNIX comes with an extensive collection of online help pages called man pages (short for manual pages). The man pages are the authoritative documentation about the system.

This is a web-accessable front end for the man pages generated by the packages in the GNU AVR toolchain, namely: AVR-gcc, AVR-binutils and AVR Libc.

Continue reading ‘AVR Toolchain - Build 2008-04-15 - Man Pages’ »

  • Categories

  • Need Code Written?

  • Need a Coding Job?

  • Tags

  • Archives