How To Create New MySQL User In Ubuntu
Few days ago I created a tutorial on how to create new database and table in mysql, in ubuntu and using GUI tool. Now, in this tutorial, I'll show you how to create new MySQL user using the same GUI tool.
Copy 3MU Playlist to Directory
One day, I want to copy music from my amarok playlist's to my cellphone. This playlist has so many files that spread across directories. As a php ninja, I create a php script to do the hard work>:).
Here's the script if you want to try:
<?php
$playlist_file = $argv[1];
$output_dir = $argv[2];
$lines = array_map("trim", file($playlist_file));
if(!is_dir($output_dir)) mkdir($output_dir);
foreach($lines as $line)
{
if(substr($line, 0, 1) == "#") continue;
if(file_exists($line))
{
$filename = basename($line);
echo "$filename\r\n";
copy($line, $output_dir."/".$filename);
}
}
?>
Use it this way php 3mu_copier.php /path/to/3mu/files/playlist.3mu /path/as/target/copy/.
Get Battery Status from Console with PHPCLI
Hahahaha, aku jadi inget ucapan... duh, ucapan siapa ya, lupa aku.
Problem / Limitasi akan membuat seseorang menjadi kreatif.
Contohnya ini (narsis boleh dong, blog sendiri koq
) ), karena main game mode fullscreen, gak bisa liat status baterai di Tray menu. Tapi masih bisa liat console (again, dengan sihir dari yakuake). tapi kalo lagi main males dong di ganggu dengan liat barus status yang panjang, mending to the point aja. Maka, jadilah script berikut ini. dia akan membaca /proc/acpi/battery/BAT1/info dan /proc/acpi/battery/BAT1/state untuk menghasilkan nilai berapa persen sisa baterai laptop sekarang.
Silahkan diambil dan dimodif sesuai kebutuhan.
#!/usr/bin/php
<?php
//read_bat_status.php
$debug = false;
$bat_infox = file('/proc/acpi/battery/BAT1/info');
if($debug) print_r($bat_infox);
foreach($bat_infox as $idx => $bat_info){
$bat_infox[$idx] = explode(':', $bat_info);
}
if($debug) print_r($bat_infox);
$lfCapacity = 0;
foreach($bat_infox as $idx => $bat_info){
if($bat_infox[$idx][0] == 'last full capacity'){
$lfCapacity = trim($bat_infox[$idx][1]);
}
}
if($debug) echo '$lfCapacity : '.$lfCapacity."\n";
$bat_statex = file('/proc/acpi/battery/BAT1/state');
if($debug) print_r($bat_statex);
foreach($bat_statex as $idx => $bat_state){
$bat_statex[$idx] = explode(':', $bat_state);
}
if($debug) print_r($bat_statex);
$rmCapacity = 0;
foreach($bat_statex as $idx => $bat_state){
if($bat_statex[$idx][0] == 'remaining capacity'){
$rmCapacity = trim($bat_statex[$idx][1]);
}
}
if($debug) echo '$rmCapacity : '.$rmCapacity."\n";
$currPercent = ($rmCapacity * 100) / $lfCapacity;
echo 'Battery Power Remaining : '.$currPercent." %\n";
?>
Cara penggunaannya, tinggal php read_bat_status.php. Tapi sebelumnya install dulu ya paket php-cli dengan sudo apt-get install php5-cli.
Check Battery State in Ubuntu
If you use Laptop and Ubuntu, you can check whether your current battery status is in good condition of need a replacement. Just type this command in your shell:
cat /proc/acpi/battery/BAT1/info
Depending on your hadware config, you'll see result like this :
present: yes design capacity: 6600 mAh last full capacity: 6600 mAh battery technology: rechargeable design voltage: 14800 mV design capacity warning: 660 mAh design capacity low: 198 mAh capacity granularity 1: 264 mAh capacity granularity 2: 3780 mAh model number: Primary serial number: battery type: Lion OEM info: Hewlett-Packard
If last full capacity is lower than design capacity than your battery is slowly going to it's end.









