Download YouTube videos using Java

From time to time we all have needed to show a YouTube video where no Internet connection is available. This program will allow you to download a video from YouTube for later playback. It is important to say that YouTube constantly changes its video URL, so someday it may need some rework. The following code was tested on Aug 12, 2012 and it works. Have a good day.  /** * YouTubeDownloader * * Modified by Andres Jaimes https://andres.

How to create a simple gradient in C#

Creating a simple gradient using two colors is very simple: Rectangle rect = new Rectangle(0, 0, 100, 100); LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, Color.Blue, 90); e.Graphics.FillRectangle(lgb, rect); This code will generate a gradient in the given rectangle that goes from white to blue in a vertical way (see last parameter in constructor). In this case, e, is any class that encapsulates the System.Drawing.Graphics class. Once the gradient is ready, well, you have to actually draw it by calling the FillRectangle function.

Printing in C# – The easy way

Believe me, it is easy. As with any class, before we can use any of the Classes, Events and Objects available to us in the .Net Framework we need to import the Namespaces we need. For this we need 3 namespaces. VB.Net users only required 2 because VB.Net assumes the System Namespace, whereas C# isn’t so kind: System System.Drawing System.Drawing.Printing These 3 Namespaces contain everything we need for this class, so you will need to add the following lines to the top of your class file:

How to know if a hex color is light or dark

There is a simple way to know this. The following code takes white (#ffffff) divided it by two as our reference color. If the comparing color is lower than the reference color, then the given color is dark, otherwise it’s light color. function isLightOrDark($hexcolor) { return (hexdec($hexcolor) > 0xffffff/2) ? 'light color' : 'dark color'; }

How to choose a printer using C#

You can assign a printer and other settings by using the basic PrintDocument and PrintDialog controls properties. Look at the next example: if (printDialog.ShowDialog() == DialogResult.OK) { printDocument.PrinterSettings.PrinterName = printDialog.PrinterSettings.PrinterName; printDocument.PrinterSettings.Copies = printDialog.PrinterSettings.Copies; }

Some words on Java, C# and C++

I have always considered myself a C++ guy. That was one of the first languages I learned. But, life has taken me through many different paths, and I have needed to learn others. It was seven years ago, when I tried my first cup of Java and I realized objects were a must: Why did I need to create an additional class to return a compound value? another file?, I could do a “one-liner” in C++.