Automatic login with SSH private key in PuTTY
These steps will enable you to automatically login to a remote computer through SSH protocol with PuTTY.
- Run PuTTYgen and generate a new SSH-2 RSA key.
- Enter some comment and a passphrase.
- Save the private key to your.ppk file.
- Copy the public key from the text field which looks like ssh-rsa AAA… to the clipboard. Save it to your remote computer at $HOME/.ssh/authorized_keys file. Make sure the key can be read/written by your user: chmod -R 600 .ssh.
- Run Pageant, click Add key, select your.ppk file and enter the passphrase. Don’t forget it. You’ll have to reenter the passphrase every time you run Pageant.
- Time to open up PuTTY. Under Connection / SSH / Auth category select your.ppk in the field Private key for your authentication. You may also want PuTTY to choose the username for you. It can be set under Connection / Data category.
- Connect!
This trick might not work if your user’s home directory is shared with another user from the same group but unfortunately .ssh and authorized_keys are owned by him. Those need group read and write (660) permissions. However, sshd needs requires 600 permissions. This can be bypassed by setting StrictModes to no at /etc/ssh/sshd_config. Security may suffer, but hey - you have to do what you have to do, right?
Setup Subversion on CentOS and connect through svn+ssh in Eclipse
These steps describe how to establish SVN collaboration environment on Linux CentOS server and Eclipse IDE.
Server configuration
- Create a shared directory dedicated to SVN users: http://www.cyberciti.biz/faq/linux-setup-shared-directory/.
- Install Subversion on your server: yum install subversion (don’t forget do sudo if not logged in as root).
- Create a repo directory: mkdir $HOME/some-repo ($HOME stands for /home/some-user).
- Establish a repository: svnadmin create $HOME/some-repo
Eclipse configuration
- Download Eclipse Subversive from http://download.eclipse.org/releases/indigo.
- Right-click on your project in the Package Explorer and choose menu item Team / Share project.
- In the wizard, select SVN. Install SVN connectors if needed.
- Provide the following data:
- URL: svn+ssh://some-user@example.com/home/some-user/some-repo
- Username: some-user
- And user’s password.
- Do the initial commit or checkout depending on where the existing code is located.
"With Sun Microsoftware’s help, the PHP of today (as opposed to yesterday) is a fully Orient Objected language suitable for cross flatworm use on a variety of scalable architectures. No one really knows what any of that means, but it sounds very good in the brochures."
Uncyclopedia
(Source: uncyclopedia.wikia.com)
Single (monolithic) controllers in OOP
Sometimes I need to do some fancy coding in PHP but do not want to overcomplicate my projects with all those trending tools and frameworks. I simply scrape a single class which provides project’s functionality within its scope.
Now I know it’s not the best practice to write monolithic controllers, but seriously, I’m not doing anything nasty either. A lot of `monolithic` things are awesome, e.g. this “Nokia 3310” phone; it’s handy and durable.
This is a perfectly valid PHP script:
<?php
global $data;
function get_some() {
global $data;
$data = 'A well known fact';
}
function get_all() {
global $data;
$data .= ' and a secret';
}
function login() {
// Check login...
return TRUE;
}
get_some();
if(login()) {
get_all();
}
echo $data;
There’s nothing wrong with this CodeIgniter MVC controller either:
<?php
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('User_model');
$this->load->model('Data_model');
// Model implementation is arbitrary...
}
public function index()
{
$this->Data_model->get_some();
if($this->User_model->login())
{
$this->Data_model->get_all();
}
$this->Data_model->print_data();
}
}
Instead of going dirty with procedural PHP or overcomplicating it with a MVC framework, you may consider writing your app as a class (and instantiate it afterwards). As in (almost) every MVC controller, the point is to have all available resources at your disposal within a single class avoiding the use of global $variables. No separate files for a small project is also a plus.
Here we go:
<?php
class App {
private $data;
public function __construct() {
$this->get_some();
if($this->login()) {
$this->get_all();
}
echo $this->data;
}
public function get_some() {
$this->data = 'A well known fact';
}
public function get_all() {
$this->data .= ' and a secret';
}
public function login() {
// Check login...
return TRUE;
}
}
$app = new App();
Quite neat, isn’t it?
Maintaining JavaScript float precision
Sometimes in JavaScript (and other languages) float numbers lose precision, e.g. 1.991 * 100 would be 199.10000000000002. That happens due to CPU limitations. Quite brutal but effective solutions exists.
function maintainFloatPrecision(number) {
if(number%1 == 0) { // Check if number has a remainder.
return number;
} else {
var str = "" + number;
if(str.match(/\d+\.\d*0{6,}\d/)) {
pos = str.search(/0{6,}\d/g);
return number.toFixed(pos - 2);
} else if(str.match(/\d+\.\d*9{6,}\d/)) {
pos = str.search(/9{6,}\d/g);
return parseFloat(number.toFixed(pos - 1));
} else {
return number;
}
}
}
Note: This function proves that 100 ÷ 3 × 3 = 100. :)
yum tips
- Configuration is usually located at /etc/yum.conf or /etc/yum.repos.d
- Config parameter exclude filters out packages according to a wildcard, e.g. exclude=*.i386 *.i586 *.i686 excludes packages of 32 bit architectures.
- If you change config parameter keepcache from 0 to 1, all downloaded RPMs will be cached at /var/cache/yum.
Using Bitbucket with Eclipse and msysgit
- Register at Bitbucket (https://bitbucket.org/).
- Install msysgit (http://code.google.com/p/msysgit/).
- Get a SSH key (in Git Gui tool click menu Help / Show SSH Key) and add it to your Bitbucket account (https://bitbucket.org/account/).
- Create/clone your repo as shown in Doug’s videos: 1st video, 2nd video.