Google
 
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, October 13, 2011

RIP Dennis Ritchie (1941-2011)


My life revolves around tools and technology, the foundation of which you laid. I've loved and enjoyed The C Programming Language more than any computer text so far. May you rest in peace..

#include <stdio.h>

main(){
  printf("RIP, Dennis Ritchie!");
}

Monday, July 11, 2011

Obfuscated awesomeness in C

Recently I've been bumping into obfuscated tiny C codes that does magic. Codes that are couple of lines in length but require pages of explanation on how it works.

There are lots of these in The International Obfuscated C Code Contest page, but here are some of the cool ones I've found in other places. (I'll update this list as I bump into more)

Yahoo! Logo ASCII Animation in six lines of C
20fps, antialiased ASCII art animation of the Yahoo! logo in six lines of C.

Donut animation
Donut animation with, well, donut shaped code. More impressive version here.

Spelt Number to Decimal
Spelt number (like, one, four, etc) in four lines of C

Brainfuck interpreter in 2 lines of C
For those who didnt know Brainfuck is a programming language.

Monday, March 19, 2007

Batch jpeg image resize in linux

The (jpeg) photos we take using digital camera are just too large so to save space and bandwidth, it's better to resize them before uploading them to online photo sharing sites like Picasa or Flickr. Here's how i do it in linux..

Basically two commands are used here.
1. djpeg - decompress a JPEG file to an image file
2. cjpeg - compress an image file to a JPEG file

So to resize, i run this script on a folder containing the image files.

#!/bin/sh

mkdir resized
for i in *.JPG
do
echo 'Resizing image..' $i
djpeg -scale 1/2 $i | cjpeg > resized/$i
done


After script is done, a folder named 'resized' is created containing the resized images..


EDIT:
Both the program djpeg/cjpeg isn't installed by default, they're part of libjpeg-progs package. Under Ubuntu you can get it by

sudo apt-get install libjpeg-progs

(thanx subir dai for pointing this out)

Friday, March 16, 2007

Steps to compile Helloworld for Symbian OS using visual c++ 6 for Nokia 6600

1. the first option is choosing which SDK to use. the lower versions have less documentation and examples but have integration with visual c++ 6. the higher versions ( > 2nd edition) have no integration with visual c++ 6 but have better documentation. so i recommend to install multiple SDKs as long as space is no limit. note that multiple sdks can coexist very easily.


2. first of all install sdk 2nd edition. the only reason to install this is for visual c++ 6 integration. there are two folders inside C:\Symbian\7.0s\Series60_v20\Series60Tools named 'applicationwizard' and 'epoctoolbar'. copy them to some other location. we need this later on..

3. now uninstall the 2nd edition sdk. this sdk has a problem that the gui softwares need exactly 1.3.1 version of java and cant work with higher.. (duh)

4. now install any higher version of sdk (in our case, 2nd ed, fp2). higher versions usually have more examples and better documentations.

5. copy the help and examples from the installation folder.

6. now u may uninstall this sdk. (reason - binaries produced by higher versions maynot work with lower version models)

7. install sdk 2nd edition fp1 (aka 2.1). both '2nd edition' and '2nd edition fp1' support 7.0s Symbian OS, but the later works with any java version higher than 1.3.1 plus it has some more functionalities.

8. install java

9. install activeperl

10. Open My Computer > Properties > Advanced > Environment. Add C:\Program Files\Java\jdk1.5.0_04\bin to the PATH variable. Add .pl to PATHEXT (so that perl scripts dont need trailing .pl ** VERY IMPORTANT!!! **)

11. Perl setup usually associates perl scripts with perl. To check, My Computer > Tools > Folder Option > File Types. Go to pl extension, n check if it is setup. if not, create a new and make it to open with perl.exe

12. now add application wizard and epoctoolbar from 'applicationwizard' and 'epoctoolbar' folders we copied in step 2. instruction on how to install is given in the readme file in the folders.

13.start visual c++ 6.0 and create an application using a wizard. Suppose the application is named Helloworld and is located at c:\HelloWorld. Once the files are created, you can edit it, but lets first compile it as it is..

14. the vc++ toolbar can be used to compile but the command line is more flexible.

15. Run > cmd

16. Go to project's group folder. cd c:\Helloworld\group

17. type -

bldmake bldfiles

This makes abld.bat and some other info files..

18. to compile for emulator type,

abld build wins udeb

Meanings:
abld - build utility command
build - build the program
wins - for emulator
udeb - debug build (u means unicode)

19. now run emulator (debug) from emulator. there is the compiled application at the bottom

20. to compile for cell phone type,

abld build thumb urel
or
abld build thumb udeb

Meanings same as 18, except that thumb refers to compressed code for armi processor in the cell phone.

21. beore transferring it to phone, we need to make a package.

24. now back to command line, go to install folder n type

makesis helloworld.pkg

25. helloworld.sis is created. transfer this to the mobile phone, install n run..


enjoy!