Optimize Linux running on USB

1. Use memory instead of disk

This tip can also lead to data loss. If you do it, you will have to always shut down your computer properly from now on, because unexpected power failures will lead to data loss.

Linux usually ensures that all changes are written to disk every few seconds. Since disk writes are so slow, you can change your system to keep things in memory longer. All changes will be written to memory, and the excruciatingly slow writes to happen in the background while you continue working. This has an instant, noticeable effect, but it can lead to data loss.

Add these lines to /etc/sysctl.conf, and reboot.

vm.swappiness = 0
vm.dirty_background_ratio = 20
vm.dirty_expire_centisecs = 0
vm.dirty_ratio = 80
vm.dirty_writeback_centisecs = 0

The problem: using this tip means that your system stops writing changes to disk until you shut down or type “sync” at a command line. If your system loses power unexpectedly, you will get bad blocks. I did. You can limit the amount of data loss in the event of a power failure to one minute by setting vm.dirty_writeback_centisecs = 6000.

A side effect is that shutting down your computer will may take several minutes where it appears to be doing nothing. Don’t cut the power until it’s done, because it is busy writing all those changes to disk.

Reference: http://stevehanov.ca/blog/index.php?id=48

 

2. Using ramdisks (tmpfs) for temporary files

It is quite easy to move directories where temporary files are stored (primarily /tmp) to a ramdisk, and it can make a significant difference in performance. The following lines added to /etc/fstab cause /tmp and /var/tmp to be stored in ramdisks:

    tmpfs    /tmp       tmpfs    defaults    0 0
    tmpfs    /var/tmp   tmpfs    defaults    0 0

Reference: http://linuxonflash.blogspot.hk/2014/10/optimizing-system-performance-of-flash.html

3. noatime

By default, the ext3/ext4 filesystem updates the access time attribute on a file system object whenever it’s read. This results in even the most trivial file reads result in a write operation. Keeping the access time updated is only important for some very specific tasks which we’re not likely to come across.

Open /etc/fstab and for each mount that is on your USB storage, add a noatime parameter. For example:

/dev/mapper/vg_root-lv_root /               ext4    errors=remount-ro 0       1

Becomes:

/dev/mapper/vg_root-lv_root /               ext4    noatime,errors=remount-ro 0       1

Reference: http://ghanima.net/doku.php?id=wiki:linuxtips:runningfromusb

 

4. IO Scheduler

Reference: http://tombuntu.com/index.php/2008/09/04/four-tweaks-for-using-linux-with-solid-state-drives/

Reference: http://ghanima.net/doku.php?id=wiki:linuxtips:runningfromusb

The default IO Scheduler used by Ubuntu is cfq. Changing this to deadline will see improved performance during times where multiple processes are trying to read/write to disk. You can change the default scheduler for all devices by adding a kernel parameter into grub.

Open /etc/default/grub and find the following line:

GRUB_CMDLINE_LINUX=""

Add the elevator option:

GRUB_CMDLINE_LINUX="elevator=deadline"

Or, if you added the verbose option earlier:

GRUB_CMDLINE_LINUX="elevator=deadline verbose"

Now, use update-grub to apply your changed setting to grub.cfg and restart for the change to take effect.

sudo update-grub
sudo reboot

To see that your new scheduler has taken effect you can query which scheduler is currently in use for a specific device with this command:

cat /sys/block/<device>/queue/scheduler

delete all email in exim

To print a list of the messages in the queue, enter:

exim -bp

To remove a message from the queue, enter:

exim -Mrm {message-id}

To remove all messages from the queue, enter:

exim -bp | awk '/^ *[0-9]+[mhd]/{print "exim -Mrm " $3}' | bash

To remove all messages from the queue with specific word, enter:

exim -bp|grep “username”| awk {‘print $3’}| xargs exim -Mrm

ssh without password using certificate

Generate a pass-phraseless SSH key:

$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.

Copy your keys to the target server:

$ ssh-copy-id id@server
id@server's password: 

Now try logging into the machine, with ssh 'id@server', and check in:

.ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.

Finally check logging in…

$ ssh id@server

id@server:~$ 

You may also want to look into using ssh-agent if you want to try keeping your keys protected with a pass-phrase.


 

Usage of RAMFS and TMPFS

Tmpfs

# mkdir -p /mnt/tmp

# mount -t tmpfs -o size=20m tmpfs /mnt/tmp

Ramfs

# mkdir -p /mnt/ram

# mount -t ramfs -o size=20m ramfs /mnt/ram

Reference: http://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/

Batch script sync two folder using xcopy on windows

@echo OFF
echo :
echo : XCOPY Batch Process Started
echo :
xcopy folder1 %USERPROFILE%\Desktop\folder2/E /D /C /Y
xcopy %USERPROFILE%\Desktop\folder2 folder1 /E /D /C /Y
echo :
echo : XCOPY Batch Process Complete
echo :

reCAPTCHA PHP example

HTML

Paste this snippet before the closing </head> tag on your HTML template:

<script src='https://www.google.com/recaptcha/api.js'></script>

Paste this snippet at the end of the <form> where you want the reCAPTCHA widget to appear:

<div class="g-recaptcha" data-sitekey="{site key}"></div>

 

PHP Code

if($_SERVER[“REQUEST_METHOD”] === “POST”)
{
//form submitted

//check if other form details are correct

//verify captcha
$recaptcha_secret = “{secret key}”;
$response =file_get_contents(“https://www.google.com/recaptcha/api/siteverify?secret=”.$recaptcha_secret.“&response=”.$_POST[‘g-recaptcha-response’]);
$response = json_decode($response, true);
if($response[“success”] === true)
{
echo “Logged In Successfully”;
}
else
{
echo “You are a robot”;
}
}

,

Qadabra Payment Proof

http://www.qadabra.com/
paypal payment

Cacti – Fix the change page bug in Create New Graph Page

There is a bug of javascript in “Create New Graph Page”.

To fix this bug, you may modify the php file “html.php” and “html_utility.php” at <cacti directory>/lib/.

Change all the code from “function gotoPage” to “function goto$page_var”.

Cacti – Page Load Agent (URL monitoring)

Source: http://www.askaboutphp.com/44/cacti-using-cacti-to-monitor-web-page-loading-part-1.html

1. Included the xml template for host, data and graph.

2. Modified the php to support https & http both.

Download: pageload-agent

中文標點/符號倉頡碼

出處: http://www.openplatform.com.hk/Chinese/punct.htm

字根
符號
字根
符號
字根
符號
字根
符號
字根
符號
字根
符號
ZXAA
ZXAN
ZXBA
ZXBN
ZXCA
ZXCN
ZXAB
ZXAO
ZXBB
ZXBO
ZXCB
︿
ZXCO
ZXAC
ZXAP
ZXBC
ZXBP
ZXCC
ZXCP
ZXAD
ZXAQ
·
ZXBD
ZXBQ
ZXCD
ZXCQ
ZXAE
ZXAR
ZXBE
ZXBR
ZXCE
ZXCR
ZXAF
ZXAS
ZXBF
ZXBS
ZXCF
ZXCS
ZXAG
ZXA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