Where is Darran?

i’m somewhere around here

Working print_it.c for Sam’s Teach Yourself C Programming in 21 days

Filed under: How To — Darran at 7:14 pm on Saturday, January 8, 2011

It’ s always awesome being blessed with incorrect code snippets in beginner programming books. Luckily, I have enough sexy house music to work through anything (thank you radio 1!). If you’re looking for a working print_it.c example, look no further!

much thanks to: http://www.programmersheaven.com/mb/beginnercpp/367391/367391/newbie-programming-error/ – There are bunch of sites with code for print_it.c and programmersheaven.com was the only one that had working code.

code:

/* print_it.c-- This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>
void do_heading(char *filename);
int line = 0, page = 0;
int main( int argv, char *argc[] )
{
char buffer[256];
FILE *fp;
if( argv < 2)
{
fprintf(stderr, "\nProper Usage is: ");
fprintf(stderr, "\n\nprint_it filename.ext\n" );
return(1);
}
if (( fp = fopen( argc[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!", argc[1]);
return(1);
}
page = 0;
line = 1;
do_heading( argc[1]);
while( fgets( buffer, 256, fp ) != NULL )
{
if( line % 55 == 0 )
do_heading( argc[1] );
fprintf( stdout, "%4d:\t%s", line++, buffer );
}
fprintf( stdout, "\f" );
fclose(fp);
return 0;
}
void do_heading( char *filename )
{
page++;
if ( page > 1)
fprintf( stdout, "\f" );
fprintf( stdout, "Page: %d, %s\n\n", page, filename );
}
/* print_it.c-- This program prints a listing with line numbers! */#include <stdlib.h>#include <stdio.h>
void do_heading(char *filename);
int line = 0, page = 0;
int main( int argv, char *argc[] ){char buffer[256];FILE *fp;
if( argv < 2){fprintf(stderr, "\nProper Usage is: ");fprintf(stderr, "\n\nprint_it filename.ext\n" );return(1);}
if (( fp = fopen( argc[1], "r" )) == NULL ){fprintf( stderr, "Error opening file, %s!", argc[1]);return(1);}
page = 0;line = 1;do_heading( argc[1]);
while( fgets( buffer, 256, fp ) != NULL ){if( line % 55 == 0 )do_heading( argc[1] );
fprintf( stdout, "%4d:\t%s", line++, buffer );}
fprintf( stdout, "\f" );fclose(fp);return 0;}
void do_heading( char *filename ){page++;
if ( page > 1)fprintf( stdout, "\f" );
fprintf( stdout, "Page: %d, %s\n\n", page, filename );}

now all that’s left is:

gcc print_it.c -o print

./print print_it.c

How to Stream in High Quality with Effects to Justin.tv or ustream.tv on Ubuntu

Filed under: How To — Darran at 8:39 pm on Sunday, November 28, 2010

This is a down and dirty how-to. I found that streaming via WebcamStudio resulted in higher quality streams than streaming directly to justin.tv. This approach also opens up some options not present in the browser based streaming solution justin.tv offers. WebcamStudio is not included in the Ubuntu repositories so we will have to download it manually.

1. Download WebcamStudio from the creators site at www.ws4gl.org. This will eventually forward you to sourceforge. Grab the .deb file from here: http://sourceforge.net/projects/webcamstudio/files/

2. Install the deb file by double clicking it. This will open up the Ubuntu deb installer. The deb installer is now included in the Ubuntu Software on newer releases. Click the install button. (Note: If you have Synaptic open, the installer will hang until Synaptic is closed. This is a bug in Ubuntu)

3. WebcamStudio is installed on the Main Menu under the Sound and Video section. Click the WebcamStudio link to launch the app. You can also press Alt+F2 and type in webcamstudio.

4. Once WebcamStudio launches you will need to select your webcam under devices. Double click your webcam.

5. Everything else should be easy. Click the play button under the Source Layer section. To verify that your webcam is working, click the output menu on the menu bar and select Show Preview. This will open up a preview window.

6. As you can see the coloring is off. To fix this we are going to apply an effect by clicking the effect tab and selecting SwapRedBlue and then enabling the effect by clicking the move button.

7. Now that everything is good we are going to go to justin.tv and login to our account. Click the Go Live! button in the top right and the select webcam. If you only have one video source available on your pc, the video feed from the webcam we previously configured should be displayed.

8. Next, lets do something special with WebcamStudio. Select the Output menu on the WebcamStudio application and then select SinglePaint. This will open up another preview panel that has paint options. We can use this to paint anything on the video stream we would like. If you like these kind of things, make sure to check out the effects tab in WebcamStudio.

Please feel free to donate to www.ws4gl.org.

How to “fix” Bridged Networking in VirtualBox (Ubuntu 11.04 Host / Windows XP Client)

Filed under: How To — Darran at 7:45 pm on Saturday, November 20, 2010

Note: This is not a complete fix, but more of a hack to get internet working on client VM’s when bridged networking does not allow client VM’s to access the internet.

After switching a Windows XP VM to bridged ethernet, the XP VM was no longer able to access the internet. I found a few solutions to this problem and this one seems to be the easiest.

To fix the loss of internet when using a bridged adapter on Virtualbox, configure the VM to have both a NAT and Bridged ethernet adapter. (see the screenshots below). To do this select the VM (must be powered off), click the settings button and then navigate to the network section of the Settings wizard. Configure Adapter 1 to bridged and then enable and configure Adapter 2 to be NAT. Press OK to save the changes and then turn on the VM. Give it a few seconds for the resources to be provisioned. You should now have access to both local and internet resources from the VM.

The NAT interface will be used to connect to internet resources, while the bridged adapter will be used to connect to local resources. This allows you to RDP  or console into the VM from other computers on your local network and still have internet access on the VM.

Adapter 1 (Bridged)

Adapter 2 (NAT)

me-tv, a great program to watch tv with on ubuntu linux

Filed under: How To — Darran at 8:07 pm on Sunday, September 5, 2010

There are quite a few programs for watching TV with on linux, but the best one I have found is me-tv! You can download me-tv from https://launchpad.net/me-tv/+download or via your distributions package manager. It makes scanning for channels, adding channels, watching TV, and recording shows a cinch. Big up to me-tv!

Some Lightweight Browsers

Filed under: How To — Darran at 1:32 am on Sunday, December 6, 2009

I have broadband at home, but sometimes during the travels I end up at a library, internet cafe, or public wifi spot that is unbearably slow. When I’m on the internet I want to see what I want to see and I want it now. To deal with this unbearable situation I have been exploring lightweight browser alternatives. In this quest I have found a few that are quite good, extremely fast, and even cross platform!

My favorite so far: Links2

Links2 is a new revision of Links that supports graphics! It is extremely fast, easy to use, and a great way to browse the internet without the clutter. Sites like Facebook will not load, but for reading the news it does really well! If you feel like you don’t need graphics, try just plain Links. It can be used from the terminal and is more than enough to enjoy the web experience.

Close, but no cigar: Dillo

Dillo is another lightweight alternative. Supporting tabbed browsing, Dillo is fast and lightweight, but for some reason lacks the charm of Links. It also seems to crash on my Ubuntu 9.10 install. A major downer.

For those that are feeling adventurous: Opera Mini beta 2 with Microemulator

Opera Mini is by far the best browser I have found in the mobile arena. Why not use it on the computer? If you don’t mind doing a little dirty work, you can get Opera Mini running on your desktop. It is not as fast as Links2 or Dillo, but the browsing experience is closer to what you would experience on Firefox, Chrome, or IE. Opera Mini is an impressive browser, and on a slow connection it makes a great Desktop browser. Opera Mini has a password manager and supports cookies! YUM!

Full fledged browser (not lightweight): Google Chrome

With the addition of Extensions to Google Chrome, I have almost fully transitioned from Firefox to Chrome! If you haven’t tried it out yet, please do. You will most likely be thoroughly impressed with its’ speed and generous real estate dedicated to browsing!

Next Page »