For a site recently I have been working, I had to determine whether a background color is dark or bright. My target was to watermark it with contrast color. If its too bright, I’d use black. For dark color I’d use white. Its so simple to think. But not easy to find.
The main Idea was to find the Luminance of a color (capital Y) . If the luminance is enough high water mark it with dark color and vice versa. This will make a contrast so watermark will always visible be.
To find the Luminance of a color (Y) this forumula is used
Y = 0.2126 R + 0.7152 G + 0.0722 B
Here R, G and B are the Red, Green and Blue component of a color. Here the constant values are determined by the contribution factor of intensity perceived by human eye. See the wiki. Now if Y is higher than 128 then its brighter color and you need to use dark color for water marking and use bright color for Y is less than 128.
If you have to do a lot of ssh, scp for a remote server you might find it annoying that it asks for password. It asks for password in a separate tty so you can not even automate it. If typing password bothers you too much you can change it so it wont ask you again. We are not turning of any authentication or disabling anything. We’ll just use a key file thats it.
Say your server name is server. And you are in a linux box. Follow these steps.
- In the terminal run
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shiplu/.ssh/id_rsa):
- In the ‘Enter file in which to save the key’ prompt type a file name where you want to store the key. Dont just press enter which will overwrite the current key file. Suppose you enter my-key.
- It’ll ask for a passphrase twice. Dont put anything. Just press enter twice to make it password less.
- You’ll see two files my-key and my-key.pub is created. Now copy the my-key.pub to your server by scp/rcp/rsync. This will be the last time you are copying something with password!
- Login to the server. Remember the login username. On the serverrun this command.
cat /path/to/my-key.pub >> ~/.ssh/authorized_keys
This command will add the public key in .ssh/authorized_keys in login users home directory (~).
- Now from the workstationyou can login without password by
ssh -i /path/to/my-key -l LOGIN_USERNAME server
- For later convenience, put this in your
alias server_ssh='ssh -i /path/to/my-key -l LOGIN_USERNAME'
alias server_scp='scp -i /path/to/my-key -l LOGIN_USERNAME'
Now you can login easily by
Today Ayon came up with a problem that he needs to convert English digits to Bangla. The Input would be something like “1 ডলার = 81.55 টাকা” and the output should be “১ ডলার = ৮১.৫৫ টাকা”. How to do it?
Its very easy to do. In fact most developers will be able to do it within few minutes. I just want to share my solution.
I use PHP’s str_replace function.
$output = str_replace(range(0, 9),$bn_digits, $input);
Thats it. You can wrap it with a function and re use it.