Thursday, November 24, 2011

Network settings on Windows Chrome different from system settings

Chrome supports the following proxy-related command line arguments:

--no-proxy-server

This tells Chrome not to use a Proxy. It overrides any other proxy settings provided.

--proxy-auto-detect

This tells Chrome to try and automatically detect your proxy configuration. This flag is ignored if --proxy-server is also provided.

--proxy-server==[:];.. | [:] | "direct://"

This tells Chrome to use a custom proxy configuration. You can specify a custom proxy configuration in three ways:

1) By providing a semi-colon-separated mapping of list scheme to url/port pairs.
For example, you can specify:
--proxy-server="http=foopy:80;ftp=foopy2"
to use HTTP proxy "foopy:80" for http URLs and HTTP proxy "foopy2:80" for ftp URLs.

2) By providing a single uri with optional port to use for all URLs.
For example:
--proxy-server="foopy:8080"
will use the proxy at foopy:8080 for all traffic.

3) By using the special "direct://" value.
--proxy-server="direct://" will cause all connections to not use a proxy.

--proxy-bypass-list

This tells chrome to bypass any specified proxy for the given list of hosts. This flag must be used (or rather, only has an effect) in tandem with --proxy-server.
The list of hosts is given in a comma-separated list of (|)[:] entries. Note that trailing-domain matching doesn't require "." separators so "google.com" will match "igoogle.com" for example.


For example,
--proxy-server="foopy:8080" --proxy-bypass-list="*.google.com;*foo.com;127.0.0.1:8080"
will use the proxy server "foopy" on port 8080 for all hosts except those pointing to *.google.com, those pointing to *foo.com and those pointing to localhost on port 8080.
igoogle.com requests would still be proxied. ifoo.com requests would not be proxied since *foo, not *.foo was specified.

--proxy-pac-url=

This tells Chrome to use the PAC file at the specified URL.

For example,
--proxy-pac-url="http://wpad/windows.pac"
will tell Chrome to resolve proxy information for URL requests using the windows.pac file.

Saturday, June 25, 2011

DIY - Very LOW COST emergency charger

Ever thought about making an adventure travel into the wilderness, but not wanting to get rid of your phone, MP3 or GPS? What if the trip takes several days and you've no place to charge your equipment? You could buy a solar charger, which are not that cheap and take really long to charge. You could have a spare batery for your phone, but then again it's not cheap and in some cases it's annoying to make the replacement. Or you could use spare and very low cost parts and build one yourself, giving you the joy of using something self made.

With simple AA chargeable batteries you can give some precious juice to your portable equipment to keep it running. With the benefit that you can charge the batteries again as soon as you get to civilization and you can use as many battery sets as your back can handle.

The AA chargeable batteries provide a maximum voltage around 1.25V instead of the alkaline non chargeable ones (1.5V). Connecting them in serial mode will give your equipment approximately 5V, which is the tension needed for the USB charged devices.

  1. micro USB connector ( 1€ )
  2. 4 AA battery socket holder ( 0.3 € )
  3. 9V battery connector snap ( 0.17 € )
  4. soldering connections and silicon glue
Since I couldn't find a place selling a micro USB connector, just bought a cable in a chinese shop and cut the part i needed. After that, the only tricky part is soldering the cables: make sure you connect red with red and black with black. The silicon glue will make the connection isolated and robust since the wires are very thin.

If you want you can even connect several distinct adapters instead of only micro USB.

Another important thing to keep in mind are the batteries capacity! They should be higher than your equipments. For example my Galaxy S has a 1500mAh battery, meaning I've to use at least the same capacity or it won't make a full charge. 

Monday, May 9, 2011

Hypnotic kamikaze burst in HTML5

Today, inspired by japanese kamikazes created another experiment using Canvas of HTML5.

Move the mouse around for some cool and hypnotic effect.

Saturday, April 2, 2011

HTML5 VideoWall Experiment

As an experiment video on HTML5, I made a VideoWall in Javascript. It copies the imageData from a video hidden outside the screen and creates some cool effects. Also added a reflection using CSS3 which makes a great effect and it's very easy. The video is in WebM format.

The developing was really straightforward, and the performance is not that bad.

Watch it here.

Only tested it on Chrome, not sure it will work on other browsers.



Video credits to Benny Benassi.

Thursday, March 17, 2011

SECURITY_ERR on Chrome using getImageData()

When playing a little with Canvas HTML5, I stumbled upon a Javascript exception SECURITY_ERR. After some search I found out that Chrome throws this exception if you're running it on as local file ( file:/// ) or using on a image from different domain.

If you want to disable this for a while just to make your development, you can start Chrome from command line with the switch --allow-file-access-from-files.

Example for Mac OS X:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files&

Saturday, February 26, 2011

Resistor value calculator in HTML5

A resistor is a two-terminal electronic component which implements electrical resistance as a circuit element. When a voltage V is applied across the terminals of a resistor, a current I will flow through the resistor in direct proportion to that voltage. The reciprocal of the constant of proportionality is known as the resistance R, since, with a given voltage V, a larger value of R further "resists" the flow of current I as given by Ohm's law.


Most axial resistors use a pattern of colored stripes to indicate resistance. Surface-mount resistors are marked numerically, if they are big enough to permit marking; more-recent small sizes are impractical to mark. Cases are usually tan, brown, blue, or green, though other colors are occasionally found such as dark red or dark gray.
Early 20th century resistors, essentially uninsulated, were dipped in paint to cover their entire body for color coding. A second color of paint was applied to one end of the element, and a color dot (or band) in the middle provided the third digit. The rule was "body, tip, dot", providing two significant digits for value and the decimal multiplier, in that sequence. Default tolerance was ±20%. Closer-tolerance resistors had silver (±10%) or gold-colored (±5%) paint on the other end.


Four-band identification is the most commonly used color-coding scheme on resistors. It consists of four colored bands that are painted around the body of the resistor. The first two bands encode the first two significant digits of the resistance value, the third is a power-of-ten multiplier or number-of-zeroes, and the fourth is the tolerance accuracy, or acceptable error, of the value. The first three bands are equally spaced along the resistor; the spacing to the fourth band is wider. Sometimes a fifth band identifies the thermal coefficient, but this must be distinguished from the true 5-color system, with 3 significant digits.
For example, green-blue-yellow-red is 56×104 Ω = 560 kΩ ± 2%. An easier description can be as followed: the first band, green, has a value of 5 and the second band, blue, has a value of 6, and is counted as 56. The third band, yellow, has a value of 104, which adds four 0's to the end, creating 560,000 Ω at ±2% tolerance accuracy. 560,000 Ω changes to 560 kΩ ±2% (as a kilo- is 103).

To try out EaselJS (a javascript library for working with the html5 canvas element) and inspired by Resistor Colour Wheel I wrote a small experiment, that can help finding the value of resistors: HTML5 Resistor calculator.




ALERT! This experiment won't work at all in Internet Explorer. You need Chrome, Firefox, Safari or any other browser supporting HTML5.

Tuesday, February 22, 2011

Aventail Connect VPN on Mac OS X

Here's a tip that can save you some trouble. If you use SonicWall Aventail Connect to make VPN connections on Mac OS X, you'll run into the same problem I did eventually. If you system crashes while using the Aventail it won't start again unless you cleanup some files.

The files are located in:


/Users/<YOUR USER>/Library/Application Support/Aventail/run


with the names: SEM.pid and SEM.sock.


Just remove both and Aventail will start and connect normally.

Friday, February 18, 2011

Linux / Mac OS X cleaning music library

If you love to listen to music, you'll probably have a huge MP3 library. Imagine that you gathered a lot of MP3 and you never bothered to keep the library clean until it was too late, and now you've a massive amount of folders and mp3 files all together with trash ( .txt, .url, .nfo, etc etc ... ) and you decided it was the time to clean it up.

You could do it the hard way, using OS X "Spotlight", finding and removing the stuff you don't want or you can do it the smart way with the beauty of command line shell.

Here's a simple and very useful command that will remove all unwanted files keeping only the ones you want. Just fire up the command shell to the folder which is the base of your library and run the following command:


find . ! \( -iname '*.mp3' -o -iname '*.wma' -o -iname '*.m4a' -o -iname '*.cue' -o -iname '*.wav' \) -type f -exec rm {} \;

You can add another set of file extensions to ignore by appending -o -iname '*.newExtension' inside the parentheses.

Friday, January 28, 2011

Flatr - Example of references inside Closures in PHP

Last post I wrote a small example showing how to use Closures in PHP, the recursive way. Today I'll show you how to use a paramater passed by reference to convert a complex object structure in a flat array, with elegance and simplicity.

Without delay here's the Flatr function:

// Example structure
$obj = new stdClass();
$obj->prop1 = 'hello';
$obj->prop2 = new stdClass();
$obj->prop2->prop2 = 'there';
$obj->prop2->prop3 = 'world!';
/**
 *
 * @param stdClass $obj
 * @return array
 */
function flatr($obj) {
    $ret = array();

    $recursiveWalk = function( $baseObject ) use (&$recursiveWalk, &$ret) {
        if (is_object($baseObject)) {
            foreach($baseObject as $propValue) $recursiveWalk($propValue);
        } else {
            $ret[] = $baseObject;
        }
    };
    $recursiveWalk($obj);

    return $ret;
}
var_dump(flatr($obj));


This will output:

array(3) { [0]=> string(5) "hello" [1]=> string(5) "there" [2]=> string(6) "world!" }

This little function is not ready to handle arrays inside the object structure. But the required changes are not hard to make.

Next post I'll demonstrate a practical usage for this function.

Thursday, January 27, 2011

PHP Closures - a practical example - the recursive way

Something fresh and new at PHP are Closures: anonymous functions assigned to variables. Most common usage for Closures is the handling of events as Callback functions, because you can easily pass them as parameters.

In my practical example I created a function that converts any object to a simple XML string, getting the node names from the property names of the objects. Since the object structure is a tree, nothing better than a recursive function to get the job done. I use a Closure as a recursive function, which makes the code much simpler, cleaner and elegant.



/**
 *
 * @param StdClass $obj
 * @param string $baseName
 * @return string
 */
function object2xml($obj, $baseName) {
    $ret = '<' . $baseName . ">\n";

    $recursiveWalk = function( $baseObject, $level ) use (&$recursiveWalk) {
        $recRet = '';
        foreach($baseObject as $k => $child) {
            $next = $recursiveWalk($child, $level + 1);
            if ($next === '') {
                $recRet .= str_repeat(' ', $level * 4) . '<' . $k . "/>\n";
            } else {
                $recRet .= str_repeat(' ', $level * 4) . '<' . $k . ">\n" . $next;
                $recRet .= str_repeat(' ', $level * 4) . ' . $k . ">\n";
            }
            
        }
        return $recRet;
    };
    $ret .= $recursiveWalk($obj, 1);


    return $ret . " . $baseName . ">\n";
}
?>
The example usage for this code follows:



$obj = (object) array(
    'level1_1' => (object) array(
        'level2_1' => (object) array(
            'level3_1' => (object) array(

            ),
            'level3_2' => (object) array(

            )
        ),
        'level2_2' => (object) array(

        )
    )
);
print object2xml($obj, 'root')
?>

 Notice the "use (&$recursiveWalk)"! To be able to call the function inside itself you need to pass it by reference to the Closure.