how to use default parameter in JS function

http://www.markhansen.co.nz/javascript-optional-parameters/

Import is:

function connect(hostname, port, method) {
    hostname = hostname || "localhost";
    port = port || 80;
    method = method || "GET";
}

The short-circuit OR operator || returns the left side if the left argument is truthy (evaluates to truein conditionals), otherwise it checks if the right argument is truthy, returning it. We can use this shortcut because undefined is falsy: in conditionals, undefined evaluates to false.

This shortcut approach is a very common idiom, but it does have a disadvantage: You can’t use for any argument that could accept a falsy value: false0nullundefined, the empty string "", and NaN.

Using the || shortcut will override any falsy input value. If you expect a falsy value, you must explicitly check for argument === undefined.

D-Link DIR-615 Route as WLan Repeater Bridge

Last week worked my old DWL-810+ Wlan Bridge (cost 60 EUR 6 years ago ) not any more. Yesterday I bought a DIR-615 H1 W-Lan Route for 15 EUR. Today I refresh the firmware with DD-WRT v24 PreSP2 Build 21061and set it as a Repeater-Bridege. It work fine.

Link: http://www.dd-wrt.com/
Firmware: http://www.dd-wrt.com/routerdb/de/download/D-Link/DIR-615/H1/H2/dlink-dir615h-factory-webflash.bin/3974

Wiki about config as Repeater-Bridge: http://www.dd-wrt.com/wiki/index.php/Repeater_Bridge

 

 

 

mysql sort with FIND_IN_SET

if you want to sort a colum  not with the standard up/ down order, you can use FIND_IN_SET in ORDER BY.

The functzion Find_in_set:

SELECT FROM FIND_IN_SET(„b“, „a,b,c“)

Just return 2, the position where matched.

Use in ODER BY Example:

SELECT * FROM Product

WHERE id IN ( 6,5,4)

ORDER BY FIND_IN_SET(id, „6,5,4“)

 

add branch display in bash

function parse_git_branch_and_add_brackets {
git branch –no-color 2> /dev/null | sed -e ‚/^[^*]/d‘ -e ’s/* \(.*\)/\ \[\1\]/‘
}
PS1=“\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ “

add into .bashrc

 

 

install PHPUnit under Mac OS 10.6 Snow Leopord

first, read the following Link:

http://kubyshkin.ru/posts/phpunit-on-mac-os-x-snow-leopard-10-6.html

Then if you get problem with symfony/YAML version conflict  like:

phpunit/PHPUnit requires package „symfony/YAML“ (version >= 1.0.2, version <= 1.0.2), installed version is 1.0.6
No valid packages found
install failed

Just uninstall it with:

sudo pear uninstall symfony/YAML
uninstall ok: channel://pear.symfony-project.com/YAML-1.0.6

then install old version like this:

sudo pear install symfony/YAML-1.0.2
downloading YAML-1.0.2.tgz …
Starting to download YAML-1.0.2.tgz (9,299 bytes)
…..done: 9,299 bytes
install ok: channel://pear.symfony-project.com/YAML-1.0.2

Now you can install PHPUnit :

sudo pear install phpunit/PHPUnit
downloading PHPUnit-3.6.12.tgz …
Starting to download PHPUnit-3.6.12.tgz (120,240 bytes)
……………………..done: 120,240 bytes
install ok: channel://pear.phpunit.de/PHPUnit-3.6.12

 

Now to check phpunit

phpunit –version
PHPUnit 3.6.12 by Sebastian Bergmann.

Done!

Bring the old Scanner Medion MD90092 to work under Snow Leopord 10.6.*

I got a old scaner Mediaon MD90092 without Driver CDs for two Euros from „flohmarkt“. The MD90092 is a OEM Product from Microtek Hompage. I need it to run under Mac OS 10.6.8. So I download the scanpotter_1050.dmg (173.4 MB) from Microtek homepage and installed. It works! Great. And the scanner can not work with meine PC with XP. Strange.

 

 

Problem with change checkbox status more than 2 times under jquery 9+

Today I got a problem with the checkbox. I wrote a very simple select all/deselect all feathers with jquey. something like that:

$('.mycheck').attr("checked", checked); //select all

and

$('.mycheck').removeAttr('checked'); // deselect all

The Problem is, the code work only once. After the second time,the checkbox will not be checked, even if a attriube „checked“ is already attached in DOM.

So I found the post in stackoverlfow: http://stackoverflow.com/questions/14494467/jquery-1-9-checkbox-not-checked-second-time-after-once-it-unchecked

use

$("#add_cart_checkbox").prop("checked", true) ;

has solved the problem.