Minggu, Januari 08, 2012

MySQL : mysqldump with -w option on Windows XP

Case : You have a big size of mysql database table on windows xp machine and you want to dump database table with "where" condition
Solution : using -w option

set_time_limit(0);

$username = "root";
$password = "toor";
$hostname = "localhost";
$sConnString = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");

$connection = mysql_select_db("Country",$sConnString)
 or die("Could not select DB");

$sql = "select * from tblkelurahan where left(KelurahanID,4)='3277'";
$query = mysql_query($sql);

while ($fetch = mysql_fetch_object($query)) {
 $namafile = $fetch->KelurahanID;
 $command = "C:xampp\\mysql\\bin\\mysqldump.exe --add-drop-table -uroot -ptoor -w\"KelurahanID='$namafile'\" Indonesia tblpenduduk > $namafile.sql";
 system($command);
}

Kamis, November 24, 2011

Javascript : Reload Target / Parent Window From Second Child Window

I have problem like this guy on this link.

Solution : use window.name, and target it to reload

On parent page :
window.name = "parent_window";

On the first child page :
function open2print(id_cek_in,diskon) {
 window.open( "cek_print.php?id_cek_in="+id_cek_in+"&cetak=y&diskon="+diskon, "print","status=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=600,height=800" )
}

On the second child page :
function reloadWin(){
 var parent_window = window.open("", "parent_window");
 parent_window.location.reload(true);
}

<body onload=reloadWin();>

So when the second child window load, it will be reload parent window.

Source : http://www.codingforums.com/showthread.php?t=113902


PS : I hate javascript, too many parents and children involved :(

Kamis, November 17, 2011

Bash : Auto Delete Old Backup Files

Based on my experience on maintenance project.
It's about to create auto delete old backup files on Mandriva 2005 (Linux) server.

This article is related with this article

After create backup file there will be alot of files created in our backup folder.
So we need an auto delete old backup files.

1. Create recycle.sh
$ mcedit /recycle.sh

File content :

#! /bin/sh
find /backup | grep `date -d '1 week ago' +%Y-%m-%d` | xargs --no-run-if-empty rm

2. Edit crontab

$ mcedit /etc/crontab

File Content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 15 * * 1-6 root /bin/sh /recycle.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

Auto delete scheduled every Monday through Friday 2 pm :)

Modified from : http://unix.stackexchange.com

Bash : Auto Backup Mysql on Mandriva 2005

Based on my experience on maintenance project.
It's about to create auto backup mysql on Mandriva 2005 (Linux) server.

1. Create file backup.sh, you may using mc or pico

$ mcedit /backup.sh

File content :

#! /bin/sh
/usr/bin/mysqldump -u[username] -p[password] [database_name] > /[your_backup_directory]/[filename].sql
cd /backup
tar --remove-files -czf backup-`date '+%Y-%m-%d' `.tar.gz -R *.sql
sudo cp -f *.tar.gz /[another_backup_directory]

2. Edit your cron list

$ mcedit /etc/crontab

File content :

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
00 7-14 * * 1-6 root /bin/sh /backup.sh

3. Reconfigure your crontab

$ crontab -u[username] /etc/crontab
$ crontab -l

MySQL auto backup scheduled every Monday through Friday beginning at 7 am till 2 pm :)

Senin, September 26, 2011

phpMyAdmin : How to Import Large CSV

Case : You have a big file size csv to import to mysql using phpmyadmin
Solution : Use mysql script instead of import form from phpmyadmin (that will save you a lot of time)
Script :
LOAD DATA LOCAL INFILE 'file_name.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(column1,column2,column3);


Note : place your csv file in your phpmyadmin directory

Source : http://www.phpfreaks.com/forums/index.php?topic=343906.0

Rabu, Agustus 31, 2011

Javascript : URL Validation

function urlValidator(elem, helperMsg){
	var urlExp = /^http?\:\/\/(www\d?\d?\d?\d?\.)?([A-Za-z0-9-_]+\.)?[A-Za-z0-9-_]+((\.[A-Za-z]{2,6})(\.[A-Za-z]{2})?([0-9-_%&\?\/\.=]*))$/;
	if(elem.value.match(urlExp)){
		return true;
	} else {
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

Kamis, Agustus 18, 2011

Excel : Delete new line

Case : You have a text :

I want
to
eat

in column A1, and  you want to replace into single line : I want to eat.
This kind of thing gonna be a troublesome if you have 1000 lines to change.
Instead of replacing manual one by one, you can do this trick :

1. Press Ctrl + F
2. Switch to "Replace" tab
3. Put active cursor into "Find what" column
4. Press Alt + 010
5. Press "Replace All" button

Now all new lines will be delete.

Source : http://www.excelforum.com/excel-general/670112-deleting-new-line-character.html

Excel : Merge Spreadsheets into One Spreadsheet

Sub CopyFromWorksheets()
    Dim wrk As Workbook 'Workbook object - Always good to work with object variables
    Dim sht As Worksheet 'Object for handling worksheets in loop
    Dim trg As Worksheet 'Master Worksheet
    Dim rng As Range 'Range object
    Dim colCount As Integer 'Column count in tables in the worksheets
     
    Set wrk = ActiveWorkbook 'Working in active workbook
     
    For Each sht In wrk.Worksheets
        If sht.Name = "Master" Then
            MsgBox "There is a worksheet called as 'Master'." & vbCrLf & _
            "Please remove or rename this worksheet since 'Master' would be" & _
            "the name of the result worksheet of this process.", vbOKOnly + vbExclamation, "Error"
            Exit Sub
        End If
    Next sht
     
     'We don't want screen updating
    Application.ScreenUpdating = False
     
     'Add new worksheet as the last worksheet
    Set trg = wrk.Worksheets.Add(After:=wrk.Worksheets(wrk.Worksheets.Count))
     'Rename the new worksheet
    trg.Name = "Master"
     'Get column headers from the first worksheet
     'Column count first
    Set sht = wrk.Worksheets(1)
    colCount = sht.Cells(1, 255).End(xlToLeft).Column
     'Now retrieve headers, no copy&paste needed
    With trg.Cells(1, 1).Resize(1, colCount)
        .Value = sht.Cells(1, 1).Resize(1, colCount).Value
         'Set font as bold
        .Font.Bold = True
    End With
     
     'We can start loop
    For Each sht In wrk.Worksheets
         'If worksheet in loop is the last one, stop execution (it is Master worksheet)
        If sht.Index = wrk.Worksheets.Count Then
            Exit For
        End If
         'Data range in worksheet - starts from second row as first rows are the header rows in all worksheets
        Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End(xlUp).Resize(, colCount))
         'Put data into the Master worksheet
        trg.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
    Next sht
     'Fit the columns in Master worksheet
    trg.Columns.AutoFit
     
     'Screen updating should be activated
    Application.ScreenUpdating = True
End Sub

Source : http://www.vbaexpress.com/kb/getarticle.php?kb_id=151

Sabtu, Juli 23, 2011

PHP : Fungsi Terbilang

function kekata($x) {
 $x = abs($x);
 $angka = array("", "satu", "dua", "tiga", "empat", "lima",
 "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
 $temp = "";
 if ($x <12) {
  $temp = " ". $angka[$x];
 } else if ($x <20) {
  $temp = kekata($x - 10). " belas";
 } else if ($x <100) {
  $temp = kekata($x/10)." puluh". kekata($x % 10);
 } else if ($x <200) {
  $temp = " seratus" . kekata($x - 100);
 } else if ($x <1000) {
  $temp = kekata($x/100) . " ratus" . kekata($x % 100);
 } else if ($x <2000) {
  $temp = " seribu" . kekata($x - 1000);
 } else if ($x <1000000) {
  $temp = kekata($x/1000) . " ribu" . kekata($x % 1000);
 } else if ($x <1000000000) {
  $temp = kekata($x/1000000) . " juta" . kekata($x % 1000000);
 } else if ($x <1000000000000) {
  $temp = kekata($x/1000000000) . " milyar" . kekata(fmod($x,1000000000));
 } else if ($x <1000000000000000) {
  $temp = kekata($x/1000000000000) . " trilyun" . kekata(fmod($x,1000000000000));
 }
  return $temp;
}
function terbilang($x, $style=4) {
 if($x<0) {
  $hasil = "minus ". trim(kekata($x));
 } else {
  $hasil = trim(kekata($x));
 }
 switch ($style) {
  case 1:
   $hasil = strtoupper($hasil);
   break;
  case 2:
   $hasil = strtolower($hasil);
   break;
  case 3:
   $hasil = ucwords($hasil);
   break;
  default:
   $hasil = ucfirst($hasil);
   break;
 }
 return $hasil;
}

Source : http://maseko.com/code-snippet/php/fungsi-terbilang/

Jumat, Juli 22, 2011

Kamis, Juli 14, 2011

JQuery : Autocomplete Force Input

case : you use jquery autocomplete to replace an old style drop down menu and you want to force user to choose at least one of these input option.
solution : use a "mustMatch";

        $().ready(function() {
            $("#kategori").autocomplete("../actions/autocomplete.php?p=kategori", {
                width: 190,
                max: 2000,
                selectFirst: false,
                mustMatch:true,
            });
        });

Senin, Juni 20, 2011

Excel : Speed Up Calculation

Case : You want to delete bulk of rows (more than 50.000 rows) on excel
Solution : Use VBA
Script :

Sub delete_rows_zero()

Application.ScreenUpdating = False

Dim nMaxRow As Long, nrow As Long
nMaxRow = ActiveSheet.UsedRange.Rows.Count
For nrow = nMaxRow To 1 Step -1
      If Range("A" & nrow).Value = "delete" Then
      Range("A" & nrow).EntireRow.Delete
      End If
Next nrow

Application.ScreenUpdating = True

End Sub


Source : http://www.databison.com/index.php/how-to-speed-up-calculation-and-improve-performance-of-excel-and-vba/

Rabu, Juni 08, 2011

Install Ubuntu Perfect Server

This tutorial shows how to prepare an Ubuntu 10.04 (Lucid Lynx) server for the installation of ISPConfig 3, and how to install ISPConfig 3. ISPConfig 3 is a webhosting control panel that allows you to configure the following services through a web browser: Apache web server, Postfix mail server, MySQL, BIND or MyDNS nameserver, PureFTPd, SpamAssassin, ClamAV, and many more. 


Rabu, Mei 18, 2011

Mass User Creation in WordPress

Case : you want to add mass user in your wordpress
Script :

require( '/wp-load.php' );
wp_create_user('otto', 'password', 'otto@ottodestruct.com');
wp_create_user('fake', 'fakepass', 'fake@example.com');
...


Source : http://wordpress.org/support/topic/mass-user-creation-in-wordpress-30

Kamis, April 14, 2011

20 Things You Must Have on Your Blog

20 things you must have on your blog :
  1. SEO Design
  2. Page : Home
  3. Page : About
  4. Page : Disclaimer
  5. Page : Contact
  6. Addthis
  7. Searchbox
  8. Shoutbox
  9. Follower
  10. Popular Post
  11. Recent Post
  12. Blog Archive
  13. Blogroll
  14. Feedjit
  15. Tagcloud / Wp-Cumulus like
  16. Backlink
  17. Paging
  18. Linkwithin
  19. Share Facebook button
  20. Google Adsense sengihnampakgigi

Source : http://www.google.com