Monday, May 18, 2009

Export/Import data in MYSQL

EXPORT
mysqldump -u<user name>
-p<password> <dbname> > <dbname.sql with file path>
eg. mysqldump -uroot -padmin mydb > /mydb.sql

IMPORT
mysql -u<user name> -p<password> < <dbname.sql>
eg.
mysql -uroot -padmin < /mydb.sql

RUN SQL COMMAND FROM CONSOLE
mysql-u<user name> -p<password> -e "SQL Command"
eg.
mysql-uroot -padmin -e "INSERT
INTO NAME VALUES(10,20,'TEST');"

Tuesday, April 7, 2009

Understanding Open file limit in Solaris 10/ Open solaris

Shell level changes

To specify the file limit use

ulimit -n &lt no of files&gt

To see the changes made

ulimit -a

These limits are set and controlled by the user's shell to limit the system resources consumed by the current shell process and all it's descendants.

System level changes

To make the changes persistent across the whole machine, you'd need to tune the following settings in /etc/system

/etc/system:

rlim_fd_max
Description: "Hard" limit on file descriptors that a single process might have to open.
Minimum: 1
Maximum: MAXINT
Default: 65,536

rlim_fd_cur
Description: "Soft" limit on file descriptors that a single process can
have open.
Minimum: 1
Maximum: MAXINT
Default: 256

save and exit
reboot

Note that these settings are per process.

The plimit command can be used to find out the limitations imposed on a particular process. e.g.
plimit 1556
1556: /usr/apache2/2.2/bin/httpd -f /etc/vpanels/httpd.conf -DSSL -k start
resource current maximum
time(seconds) unlimited unlimited
file(blocks) unlimited unlimited
data(kbytes) unlimited unlimited
stack(kbytes) 10240 unlimited
coredump(blocks) unlimited unlimited
nofiles(descriptors) 65536 65536
vmemory(kbytes) unlimited unlimited

Tuesday, July 29, 2008

Home Made Wind Power Generator


How It all started??

I was wondering how to produce electricity from wind energy? I thought this when I was young and I was able to make one now :). It all started when I was removing my old 3.14" floppy drive from my computer. When I examined the drive, I got a stepper motor from that. After I had got stepper motor, I googled for a suitable wind bladge. I got some cool stuffs about making wind balade with PVC pipes. So, I started working on it and I was successfull in generating power.

Requisites

  • 1 Stepper Motor (12V)
  • 8 Diode 25V (reverse break down voltage). Any thing greater than or equal to 12V will do
  • 2 Capasitors 1000pF 16V(or some thing near that value)
  • 1 LED (this is the load)
  • Some wires
  • PVC pipe of length 70cms with diameter as 15cm or more..
  • 4 nuts with bolts
  • Some metal scraps to fix the wind blade with the stepper motor.

The Stepper Motor


Inside a stepper motor are four coils of wire located 90 degrees away from each other - i.e. at positions 12, 3, 6, and 9 o'clock. In the middle is the rotor which spins and has permanent magnets fitted around its circumference. As the rotor spins each magnet in turn approaches, passes, and moves away from each of the four coils in turn. A magnet passing a coil of wire causes electricity to flow through that coil and so each of the four coils will have different amounts of electricity flowing through it either one way or the other - alternating current.

Since a stepper motor has four coils of wire, it is said to be a four-phase motor. The advantage of this multi-phase set-up for electricity generation projects is that when one coil has no electricity flowing through it, the next coil will have reached its maximum. When the four-phases are brought together and rectified (more on rectification later) into direct current (DC), the total electricity generated therefore has a near constant voltage and current.



Place you can see stepper motors are FAX machine, Document copier, Floppy drives. I took the stepper motor from my old 3.14" floppy drive.


The Wind Blade

Cut the PVC pipe with 60cm length.

Then follow the below sketch to cut the pipe and make the blade.


I used Angled Cut as in this design and It worked really good.


The Circuit

We will be using two A/C to DC bridge as we have two coils. The circuit diagram is as follows.




Attach the wind blade with the stepper motor.

Pictures of my working model
Wind Blade

Wind Blade closer look

Stepper motor coupled with wind blade

A/C power from stepper motor

The circuit

LED glowing


Version 2 @ http://tekzgeek.blogspot.com/2011/06/home-made-wind-power-v20.html

Future Enchancements

  • Thinking to use the generated power to charge a battery.
  • This can be scaled to a larger extent and I hope this could power some home appliance.

After this I am thinking of taping solar energy to generate electric power.

-Tekzgeek

Saturday, June 9, 2007

Commanding Threads in Java


Following are source to command threads in java

Command.java

package tekzgeek.thread;

public class Command
{
public static int PAUSE=0;
public static int RESUME=1;
public static int EXIT=2;
int state=RESUME;
int command=RESUME;

synchronized public int getCommand()
{
if(this.state==this.command)
return this.state;

if((this.state==RESUME)&&(this.command==PAUSE))
{
this.state=PAUSE;
notify();
while((this.command!=Command.RESUME)&&(this.command!=Command.EXIT))
{
try
{
wait();
}
catch(InterruptedException e)
{}
}
if(this.command==Command.RESUME)
this.state=Command.RESUME;
else if(this.command==Command.EXIT)
this.state=Command.EXIT;


}
else if((this.state==Command.RESUME)&&(this.command==Command.EXIT))
{
this.state=Command.EXIT;
notify();
}
return this.state;
}

synchronized public void setCommand(int command_temp)
{
this.command=command_temp;

if(state==command)
return;

if((this.state==Command.RESUME)&&(this.command==Command.PAUSE))
{
while(this.state!=Command.PAUSE)
{
try
{
wait();
}
catch(InterruptedException e)
{}
}
}
else if((state==PAUSE)&&(command==RESUME))
{
notify();
}
else if((this.state==Command.RESUME)&&(this.command==Command.EXIT))
{
while(this.state!=Command.EXIT)
{
try
{
wait();
}
catch(InterruptedException e)
{}
}
}
else if((this.state==Command.PAUSE)&&(this.command==Command.EXIT))
{
notify();
}
}
}

WorkerThread.java
package tekzgeek.thread;
import tekzgeek.thread.Command;

public class WorkerThread extends Thread
{
Command command;
public WorkerThread(Command command)
{
this.command=command;
}
public void run()
{
boolean EXIT=false;
while(!EXIT)
{
// Do Some Work

System.out.println("Worker Thread Running.");
try
{
Thread.sleep(200);
}catch(InterruptedException e)
{}

int cmd=command.getCommand();
if(cmd==Command.EXIT)
EXIT=true;
}
System.out.println("I am done.");

}
}

Main.java
package tekzgeek.thread;
import tekzgeek.thread.Command;
import tekzgeek.thread.WorkerThread;

public class Main
{
public static void main(String args[])throws InterruptedException
{
Command command=new Command();
WorkerThread workerThread=new WorkerThread(command);
workerThread.start();

Thread.sleep(1000);

System.out.println("Main Thread is trying to Pause Worker Thread.");
command.setCommand(Command.PAUSE);
System.out.println("Main Thread Paused Worker Thread.");

Thread.sleep(1000);

System.out.println("Main Thread is trying to Resume Worker Thread.");
command.setCommand(Command.RESUME);
System.out.println("Main Thread Resumed Worker Thread.");

Thread.sleep(1000);

System.out.println("Main Thread is trying to Stop Worker Thread.");
command.setCommand(Command.EXIT);
System.out.println("Main Thread stopped Worker Thread.");
}
}


Command.java- The basic core for transfering messages between threads.
Main.java- Main Thread that commands Worker Thread.
WorkerThread.java- This thread does the work and is controlled by Main Thread.

pl note : One way command is only implemented. To go for two way communication or for feedback,create
one more command for getting feedback from worker thread.

Configure Log4j/ Log4j Example


Steps to configure Log4j and to run a simple application are
1. Download Log4j from http://www.apache.org/
2. Extract all the contents to a directory.
3. In the directory find the jar file log4j-X.X.XX.jar under directory \dist\lib. Make sure ur class path points to this jar file.
4. Create a file named Log4jDemo.java and put the following contents in it.

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class Log4jDemo
{
static Logger logger = Logger.getLogger(Log4jDemo.class);
public static void main(String args[])
{
PropertyConfigurator.configure("log4j.properties"); // or u can use file name with path eg. D:\\Demo\\log4j.properties
logger.debug("DEBUG Message");
logger.info("INFO Message");
logger.warn("WARN Message");
logger.error("ERROR Message");
logger.fatal("FATAL Message");
}

}

5. Create a new file named log4j.properties at the same directory where u have put the Log4jDemo.class file. Put the following contents in to it.


log4j.rootLogger=DEBUG, MF ,CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.CONSOLE.layout.ConversionPattern=[%t] %C at %L %-5p %c %x - %m%n

log4j.appender.MF=org.apache.log4j.RollingFileAppender
log4j.appender.MF.File=Main.log

log4j.appender.MF.MaxFileSize=100KB
# Keep one backup file
log4j.appender.MF.MaxBackupIndex=1

log4j.appender.MF.layout=org.apache.log4j.PatternLayout
log4j.appender.MF.layout.ConversionPattern=[%t] %C at %L %-5p %F (%L) %c %x - %m%n

6.Now when u run the Log4jDemo.java u get a console ouput and also saved to a file called Main.log

Writing a Content to a file in Java


import java.io.*;

public class FileWriterDemo
{
public static void main(String args[]) throws FileNotFoundException,IOException
{
File file=new File("Demo.txt"); // or u can use file name with path eg. D:\\Demo\\Demo.txt
if(!file.exists())
file.createNewFile();

BufferedWriter out = new BufferedWriter(new FileWriter(file,true));// true flag tells us to append to the exiting file.
out.write("Hello World.");
out.newLine();
out.close();
}

}
Save above contents in a file called FileWriterDemo.java

Reading a Content of a file in java


import java.io.*;

public class FileReaderDemo
{
public static void main(String args[]) throws FileNotFoundException,IOException
{
File file1=new File("Demo.txt"); // or u can use file name with path eg. D:\\Demo\\Demo.txt
BufferedReader in = new BufferedReader(new FileReader(file1));
String str;
while ((str = in.readLine()) != null) {
System.out.print(str);
}
in.close();
}

}

Save above contents in a file called FileReaderDemo.java