Menggaulimu's Blog

Apa Aja Deh, Suka-Suka Gw

Check Duplicate rows on Mysql

Table Name= "list"
SELECT firstname, lastname, list.address FROM list
INNER JOIN (SELECT address FROM list
GROUP BY address HAVING count(id) > 1) dup ON list.address = dup.address

Number of days in particular month of particular year


// Create a calendar object and set year and month

Calendar mycal = new GregorianCalendar(1999, Calendar.FEBRUARY, 1);

// Get the number of days in that month
int daysInMonth = mycal.getActualMaximum(Calendar.DAY_OF_MONTH); // 28

// Try month in a leap year
mycal = new GregorianCalendar(2000, Calendar.FEBRUARY, 1);
daysInMonth= mycal.getActualMaximum(Calendar.DAY_OF_MONTH);     // 29

Random Array

Untuk mengacak atau membikin randomize sebuah array, disini kita menggunakan Collections.shuffle, langsung saja contohnya :



String[] contohArray = {"A","B","C","D","E","F};

Collections.shuffle(Arrays.asList(contohArray))

//Untuk melihat hasil acak array bisa dengan :

for(int i=0;i<5;i++) {

System.out.println(contohArray), //hasilnya : {"B","D","A","F","E","C"}, {"A","F","C","D","B","E"}, dst...

}

//Untuk mengambil salah satu hasil acakan array tersebut bisa dengan :

System.out.println(contohArray[0]);


Happy Coding!

Generate Random Number in Specific Range

Apabila kita ingin membuat randomize angka dengan jarak (range) angka tertentu, misalnya :

membuat random data angka antara 100 s/d 315, maka coding nya adalah sbb :


Random rand = new Random();
int angkaRandom = rand.nextInt(315-100)+100;

hasil angkaRandom diatas antara 100 dengan 315 , akan tetapi angka 315 tidak ikut dalam pemilihan data.

Apabila angka 315 ingin diikutkan dalam pemilihan data maka :


Random rand = new Random();
int angkaRandom = rand.nextInt(316-100)+100;

 

Problem Installing Moxa Driver CP-168U with kernel newer than 2.6.30

error message :
/home/some_user_dir/mxser/driver/mxser.c: In function ‘mxser_flush_buffer’:
/home/some_user_dir/mxser/driver/mxser.c:1990: error: request for member ‘ops’ in something not a structure or union
make[3]: *** [/home/some_user_dir/mxser/driver/mxser.o] Error 1
make[2]: *** [_module_/home/some_user_dir/mxser/driver] Error 2

find mxser.c and mxupcie.c inside folder driver (driver/mxser.c & driver/mxupcie.c)
open the file using vi or text editor and search “tty->ldisc.ops” (without quotes) change to “tty->ldisc->ops” (without quotes)

save the files and compile again, Good luck !!

Execute Shell Command From Java

Code Example :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ExecShell {

   public static void main(String[] args) {

      String cmd = "ls -al";
      Runtime run = Runtime.getRuntime();
      Process pr = null;
      try {
         pr = run.exec(cmd);
         pr.waitFor();
         BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
         String line = "";
         while ((line=buf.readLine())!=null) {
            System.out.println(line);
         }
      } catch (IOException e) {
         e.printStackTrace();
      } catch (InterruptedException e) {
         e.printStackTrace();
      }
   }

}

Login Session di Aplikasi Desktop Java

Bikin aja 1 class nama class bebas, kemudian bikin property userLogin dan buatin getter/setter dengan
akses static.
Saat login , set property userLogin tersebut dengan username yg dipake login.
Sample :

public class UserSession {

  private static String userLogin;

  public static void setUserLogin(String userLogin) {
    UserSession.userLogin = userLogin;
  }

  public static String getUserLogin() {
    return userLogin;
  }
}

 

/*** login ***/
if (username.equals("valid_user") && password.equals("valid_password")) {
  // set username ke session
  UserSession.setUserLogin(username);
}

// Ingin nampilin ke form? tinggal panggil spt ini


lblInfoUser.setText(UserSession.getUserLogin());

MS Word 2010 : How to add Page Number in each Column

Use Word fields :
Tab Insert -> Quick Parts -> field

Place a one row, two column TABLE in the footer that aligns with your text columns. In the left cell insert:

{ = {PAGE} * 2 – 1 }

In the right cell:

{ = {PAGE} * 2 }

Insert { } field brackets, by using Ctrl+F9. Alt+F9 will let you switch between the field code and field result displays, F9 will force the displays to update.

Installing Oracle 10G on Centos 5 (32bit)

Creating Oracle User Account :


$ su - root
$ groupadd dba
$ groupadd oinstall
$ useradd -c "Oracle Software Owner" -g oinstall -G dba oracle
$ passwd oracle

Setting Oracle Environments


$ su - oracle
$ pwd #the directory has to be /home/oracle

use vi or nano to edit profile


$ nano .bash_profile

content of .bash_profile :


echo "Welcome to ORACLE Environment"

export ORACLE_BASE=/oracle</em></span>
export ORACLE_HOME=/oracle/product/10.1.0
export ORACLE_SID=oraclesid  #name of oracle instance service
export JAVA_HOME=/usr/java/jdk1.5.0_15 #Home directory for java (edit by yourself)
export PATH=$JAVA_HOME/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=/lib:$JAVA_HOME/lib:$ORACLE_HOME/lib:.

Creating Oracle Home Directory (as mention in .bash_profile)


$ su - root
$ mkdir /oracle

Change Ownership for Oracle Home Directory (/oracle)


$ chown -R oracle:oinstall /oracle

Check Installed RPMs (make sure all RPMs is Installed)


$ rpm -q binutils compat-db control-center gcc gcc-c++ glibc glibc-common gnome-libs libstdc++ libstdc++-devel make pdksh sysstat xscreensaver libaio compat-libstdc++-33 glibc-devel

Results :

binutils-2.17.50.0.6-14.el5
package compat-db is not installed
control-center-2.16.0-16.el5
gcc-4.1.2-48.el5
package gcc-c++ is not installed
glibc-2.5-49.el5_5.7
glibc-common-2.5-49.el5_5.7
package gnome-libs is not installed
libstdc++-4.1.2-48.el5
package libstdc++-devel is not installed
make-3.81-3.el5
package pdksh is not installed
package sysstat is not installed
package xscreensaver is not installed
libaio-0.3.106-5

.:: Install Package which not installed ::.

Install xorg-x11-deprecated-libs

$ yum install xorg-x11-deprecated-libs

Set Display to allow from any hosts

$ su - root
$ xhost +

Change RedHat Release

$ cp /etc/redhat-release /etc/redhat-release.orig
$ cat > /etc/redhat-release << EOF
$ Red Hat Enterprise Linux AS release 3 (Taroon)
$ EOF

After you are done with the Oracle10g installation, undo the changes you made to /etc/redhat-release

$ su - root</span><em>
$ cp /etc/redhat-release.orig   /etc/redhat-release

Checking Kernel Parameters (Important!)
To see all kernel parameters, execute:

$ su - root
$ sysctl -a

For Oracle10G, the following kernel parameters have to be set to values greater than or equal to the recommended values which can be changed in the proc filesystem:

shmmax  = 2147483648 (To verify, execute: cat /proc/sys/kernel/shmmax)
shmmni  = 4096 (To verify, execute: cat /proc/sys/kernel/shmmni)
shmall  = 2097152 (To verify, execute: cat /proc/sys/kernel/shmall)   (for 10g R1)
shmmin  = 1 (To verify, execute: ipcs -lm |grep “min seg size”)
shmseg  = 10 (It’s hardcoded in the kernel – the default is much higher)
semmsl  = 250 (To verify, execute: cat /proc/sys/kernel/sem | awk ‘{print $1}’)
semmns  = 32000 (To verify, execute: cat /proc/sys/kernel/sem | awk ‘{print $2}’)
semopm  = 100 (To verify, execute: cat /proc/sys/kernel/sem | awk ‘{print $3}’)
semmni  = 128 (To verify, execute: cat /proc/sys/kernel/sem | awk ‘{print $4}’)
file-max = 65536 (To verify, execute: cat /proc/sys/fs/file-max)
ip_local_port_range = 1024 65000 (To verify, execute: cat /proc/sys/net/ipv4/ip_local_port_range)

NOTE: Do not change the value of any kernel parameter on a system where it is already higher than listed as minimum requirement.

Edit /etc/sysctl.cont

$ nano /etc/sysctl.conf

add :

kernel.sem=250 32000 100 128
fs.file-max=65536
net.ipv4.ip_local_port_range=1024 65000
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=262144
net.core.wmem_max=262144

Download / copy Oracle 10G Source Binary to Oracle User Directory (/home/oracle)
10201_database_linux_x86_64.cpio.gz

$ gunzip 10201_database_linux_x86_64.cpio.gz
$ cpio -idmv < 10201_database_linux_x86_64.cpio
$ cd database
$ ./runInstaller

Install Windows XP dari USB Flashdisk

Syarat-syarat yang harus di penuhi:

  • Menyediakan USB Flashdisk Minimal 1 GB Kosongan
  • Komputer
  • CD Instalasi Windows XP
  • Mental Baja

Berikut caranya :

+ Download File ( PeToUSB_3.0.0.7.zip, bootsect.zip, usb_prep8.zip) klik disini untuk download
+ Buat Folder Baru dengan Nama USB_Tools dan Ekstrak File yang sudah di download tadi dalam Folder USB_Tools

  • bootsect.zip menghasilkan folder bootsect
  • usb_prep8.zip menghasilkan folder usb_prep8
  • PeToUSB menghasilkan File PeToUSB.exe

+ Copy PeToUSB.exe ke Folder usb_prep8
+ Pasang USB Flashdisk ke komputer terus lihat flashdisk ada di drive apa sebagai contoh disini saya menggunakan drive G
+ klik ganda file usb_prep8.cmd di folder \USB_Tools\usb_prep8

+ Tekan ENTER dan keluar Gambar seperti di bawah ini :

+ Centang  USB Removable
+ Di bawahnya pilih Drive USB Flashdisk yang akan digunakan untuk install
+ Centang Enable Disk Format
+ Centang Enable LBA (FAT 16 x)
+ Klik Start

+ Klik Yes
+ Jangan Tutup window PeToUSB dan cmd.exe
+ Klik Start -> Run -> ketik cmd setelah muncul Command Prompt pindah ke direktori USB_Tools dan masuk ke subdirektori bootsect (\USB_Tools\bootsect)
+ Ketik “BootSect.exe /nt52 g:” (dengan contoh Flashdisk di Drive G)

+ Tutup window PeToUSB (yg buat format usb) dan akan muncul window cmd.exe dengan beberapa pilihan

+ Tekan 1, lalu masukan drive dimana Installer XP berada
+ Tekan 2, untuk masukan lokasi virtual drive (pake drive T aja, default)
+ Tekan 3, utuk masukan lokasi drive flashdisk (contoh pake G)
+ Tekan 4, untuk mulai melakukan copy File Installer

+ Apabila ditanya Format, jawab Yes
+ Apabila ditanya Copy To USB-Drive, jawab Yes
+ Apabila ditanya change migrate.inf, jawab Yes
+ Apabila ditanya unmount virtual drive, jawab Yes

Proses Pembuatan Installer USB Telah Selesai, Gampang Kan ?

TIPS Penting Untuk Diperhatikan :
+ Saat Boot via USB Pilih No 1
+ Setelah Restart Pilih No 2
+ Setelah Restart lagi Pilih No 2

Modifikasi boot.ini yang ada di Flashdisk agar dapat berjalan lancar :
Copy Paste di bawah ini dan overwrite ke boot.ini

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS=”Microsoft Windows XP Professional” /noexecute=optin /fastdetect