crontab -l
figure out whats in your cron, copy to a file called myCron
modify the file and add the crap you want
50 13 * * * /usr/local/subversion/svnbackup.sh
this runs the script at 1:50pm every day
then copy the file into the cron:
crontab < myCron
yey!
Friday, December 08, 2006
Monday, December 04, 2006
UNIX: delete files older then X days old
This can be useful when making a rolling backup script
find /directory -type f -mtime +12 | xargs rm
/directory: your directory name that the files are under (rename appropriately)
-type f: only delete files (not subdirectories)
+12: older than 12 days old
find /directory -type f -mtime +12 | xargs rm
/directory: your directory name that the files are under (rename appropriately)
-type f: only delete files (not subdirectories)
+12: older than 12 days old
Monday, November 27, 2006
quick mod by 11
1==1 (mod 11)
10==-1 (mod 11)
100==1 (mod 11)
1000==-1 (mod 11)
Therefore 123456 == 6 - 5 + 4 - 3 + 2 - 1 (mod 11) == 3 (mod 11)
Obviously you may need to do a further % operation after adding and subtracting digits, but it should be reasonably fast.
10==-1 (mod 11)
100==1 (mod 11)
1000==-1 (mod 11)
Therefore 123456 == 6 - 5 + 4 - 3 + 2 - 1 (mod 11) == 3 (mod 11)
Obviously you may need to do a further % operation after adding and subtracting digits, but it should be reasonably fast.
Wednesday, November 08, 2006
Thursday, October 19, 2006
handy eclipse template: class quick init
public ${enclosing_type}() {
${cursor}
}
public static void main(String[] args){
new ${enclosing_type}();
}
${cursor}
}
public static void main(String[] args){
new ${enclosing_type}();
}
Wednesday, September 13, 2006
how to update ports on freebsd (better way)
first get cvsup_fastest
then make a script
#!/bin/sh
cvsup -gL2 -h`cvsup_fastest -Q -c us` /usr/share/examples/cvsup/ports-supfile
cron this or whatever
then make a script
#!/bin/sh
cvsup -gL2 -h`cvsup_fastest -Q -c us` /usr/share/examples/cvsup/ports-supfile
cron this or whatever
Tuesday, September 12, 2006
unix shell scripting: args check
usage()
{
echo "Usage: program [args] [bleee]"
}
if [ $# -eq 0 ] ; then
echo "ERROR Insufficient arguments"
usage
exit 1
fi
{
echo "Usage: program [args] [bleee]"
}
if [ $# -eq 0 ] ; then
echo "ERROR Insufficient arguments"
usage
exit 1
fi
Monday, September 11, 2006
send email on solaris 8 with xmail
/bin/mailx -s "subject" email@address.com < /path/to/message/body.txt
the message body has to be a file.
the message body has to be a file.
Tuesday, September 05, 2006
Wednesday, August 30, 2006
Friday, August 18, 2006
Unsupported major.minor version 48.0
Problem:
Unsupported major.minor version 48.0
solution:
what you are running was compiled on 1.4 and you are running 1.3 or older
Unsupported major.minor version 48.0
solution:
what you are running was compiled on 1.4 and you are running 1.3 or older
Wednesday, August 16, 2006
Cannot use javahl nor command line svn client
Problem:
svnant gives this error when i try to run the example that comes with it, or anything else
Cannot use javahl nor command line svn client
Solution:
the javahl dll file needs to be on your PATH to be able to load. svntask uses a System.loadLibrary() to load this dll, so modify your PATH variable and add the dir of where that dll is at. If you get subclipse for subversion then you can find javahl in the plugins dir, i think.
You can check what your path is by doing:
System.out.println(System.getProperty("java.library.path"));
after you change your path, you may need to reboot because windows is stupid.
svnant gives this error when i try to run the example that comes with it, or anything else
Cannot use javahl nor command line svn client
Solution:
the javahl dll file needs to be on your PATH to be able to load. svntask uses a System.loadLibrary() to load this dll, so modify your PATH variable and add the dir of where that dll is at. If you get subclipse for subversion then you can find javahl in the plugins dir, i think.
You can check what your path is by doing:
System.out.println(System.getProperty("java.library.path"));
after you change your path, you may need to reboot because windows is stupid.
Tuesday, August 08, 2006
how to annoy people using UNIX
first, do
$who
mk pts/3 Aug 8 15:07 (**********.com)
to find out who is around to annoy.
then do
$yes FATAL SYSTEM ERROR. SHUTTING DOWN | write mk pts/3
this will print FATAL SYSTEM ERROR. SHUTTING DOWN all over their terminal until you press ctrl-c
$who
mk pts/3 Aug 8 15:07 (**********.com)
to find out who is around to annoy.
then do
$yes FATAL SYSTEM ERROR. SHUTTING DOWN | write mk pts/3
this will print FATAL SYSTEM ERROR. SHUTTING DOWN all over their terminal until you press ctrl-c
Wednesday, July 12, 2006
Problem: MANIFEST.MF missing class-path inside JAR
Problem:
MANIFEST.MF missing class-path: inside JAR.
Solution:
Put a blank like at the end of the manifest file.
MANIFEST.MF missing class-path: inside JAR.
Solution:
Put a blank like at the end of the manifest file.
Wednesday, July 05, 2006
How to terminate process by name in UNIX
kill -9 `ps -ef | grep process_name | grep -v grep | awk '{print $2}'`
Note that the grep process_name should be the command that you ran. Also note that the commands after 'kill -9' are enclosed in backtiks.
Note that the grep process_name should be the command that you ran. Also note that the commands after 'kill -9' are enclosed in backtiks.
Monday, July 03, 2006
Sam's Spinach Salad
sfultong: spinach, a bunch
sfultong: slivered almonds
sfultong: garlic
sfultong: oil, salt, pepper
sfultong: mince about 2 cloves of garlic for a pound of spinach
sfultong: oh, and balsamic vinegar
sfultong: and then put the minced garlic in oil, heat on medium for about a minute, or whenever the garlic starts flavoring the oil
sfultong: at the same time, toast the almonds
sfultong: usually I just put them naked in another pan, and put them on low/medium heat
sfultong: make sure not to burn them
sfultong: and... then throw both the almonds and the garlic oil on top of the spinach
sfultong: add salt, pepper, and a bit of balsamic vinegar
sfultong: probably about half as much balsamic vinegar as oil you use for garlicing
Thursday, June 01, 2006
How to portscan with nnmap
nmap -P0 -p0-65535 127.0.0.1
-P0 == dont try to ping
-p == port range (note that its 0-65535)
obligatory man page posting:
Nmap 3.81 Usage: nmap [Scan Type(s)] [Options]
Some Common Scan Types ('*' options require root privileges)
* -sS TCP SYN stealth port scan (default if privileged (root))
-sT TCP connect() port scan (default for unprivileged users)
* -sU UDP port scan
-sP ping scan (Find any reachable machines)
* -sF,-sX,-sN Stealth FIN, Xmas, or Null scan (experts only)
-sV Version scan probes open ports determining service & app names/versions
-sR RPC scan (use with other scan types)
Some Common Options (none are required, most can be combined):
* -O Use TCP/IP fingerprinting to guess remote operating system
-p ports to scan. Example range: 1-1024,1080,6666,31337
-F Only scans ports listed in nmap-services
-v Verbose. Its use is recommended. Use twice for greater effect.
-P0 Don't ping hosts (needed to scan www.microsoft.com and others)
* -Ddecoy_host1,decoy2[,...] Hide scan using many decoys
-6 scans via IPv6 rather than IPv4
-T General timing policy
-n/-R Never do DNS resolution/Always resolve [default: sometimes resolve]
-oN/-oX/-oG Output normal/XML/grepable scan logs to
-iL Get targets from file; Use '-' for stdin
* -S/-e Specify source address or network interface
--interactive Go into interactive mode (then press h for help)
Example: nmap -v -sS -O www.my.com 192.168.0.0/16 '192.88-90.*.*'
-P0 == dont try to ping
-p == port range (note that its 0-65535)
obligatory man page posting:
Nmap 3.81 Usage: nmap [Scan Type(s)] [Options]
Some Common Scan Types ('*' options require root privileges)
* -sS TCP SYN stealth port scan (default if privileged (root))
-sT TCP connect() port scan (default for unprivileged users)
* -sU UDP port scan
-sP ping scan (Find any reachable machines)
* -sF,-sX,-sN Stealth FIN, Xmas, or Null scan (experts only)
-sV Version scan probes open ports determining service & app names/versions
-sR RPC scan (use with other scan types)
Some Common Options (none are required, most can be combined):
* -O Use TCP/IP fingerprinting to guess remote operating system
-p
-F Only scans ports listed in nmap-services
-v Verbose. Its use is recommended. Use twice for greater effect.
-P0 Don't ping hosts (needed to scan www.microsoft.com and others)
* -Ddecoy_host1,decoy2[,...] Hide scan using many decoys
-6 scans via IPv6 rather than IPv4
-T
-n/-R Never do DNS resolution/Always resolve [default: sometimes resolve]
-oN/-oX/-oG
-iL
* -S
--interactive Go into interactive mode (then press h for help)
Example: nmap -v -sS -O www.my.com 192.168.0.0/16 '192.88-90.*.*'
Monday, May 22, 2006
Neural Network based Checker AI Link
I wrote a much more detailed description of the neural network checker AI project that i worked on, it can be found here:
Clicky Click me!
Clicky Click me!
Sunday, May 21, 2006
JApplet not painting on init
my crapplet has internal JPanels, and it was not repainting on load, only when the window was resized.
solution:
add this:
solution:
add this:
Wednesday, May 10, 2006
JOptionPane Madness
String options[] = new String[]{"yes","no"};
int n = JOptionPane.showOptionDialog(frame,
"Would you like green eggs and ham?",
"A Silly Question",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //don't use a custom Icon
options, //the titles of buttons
options[0]); //default button title
int n = JOptionPane.showOptionDialog(frame,
"Would you like green eggs and ham?",
"A Silly Question",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //don't use a custom Icon
options, //the titles of buttons
options[0]); //default button title
Tuesday, May 09, 2006
some basic C command line crap
cc -o yourprog yourprog.c -I/path/to/header -L/path/to/libs
: the -o is the output file
: ie, the thing you want to run
: -c is object file
: if you did cc -c 1.c -c 2.c -c 3.c
: you'd have 1.o, 2.o, 3.o
: then you could cc -o foo 1.o 2.o 3.o
: and it would link foo from the object code
: btw
: if you use lowercase Ls
: -l math -l crypt -l thislib -l thatlib
: you can link in additionally libraries as needed
: the -o is the output file
: ie, the thing you want to run
: -c is object file
: if you did cc -c 1.c -c 2.c -c 3.c
: you'd have 1.o, 2.o, 3.o
: then you could cc -o foo 1.o 2.o 3.o
: and it would link foo from the object code
: btw
: if you use lowercase Ls
: -l math -l crypt -l thislib -l thatlib
: you can link in additionally libraries as needed
how to update ports on freebsd
cvsup -gL2 -hcvsup11.freebsd.org /usr/share/examples/cvsup/ports-supfile
Friday, March 10, 2006
WindowCloser code
i use this all the time:
|
Friday, February 10, 2006
BufferedImage needs Display under Unix
problem:
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
solution:
set java.awt.headless=true
System.setProperty("java.awt.headless","true");
unless your system needs a gui, then, you need to google.
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
solution:
set java.awt.headless=true
System.setProperty("java.awt.headless","true");
unless your system needs a gui, then, you need to google.
Thursday, February 09, 2006
A cool function
I wish i saw this when i had to do java homework, it would have helped.
to bad i never had to since reverse any numbers.
to bad i never had to since reverse any numbers.
Wednesday, February 08, 2006
RMI on UNIX problems
so now that i have my server running on Freebsd, there is a slew of related problems:
i got this on the client:
RMI connection refused problem solved.
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
when i was connecting to the bsd server which isnt localhost by the way, the error seems to stem from the way i have my hosts file setup on bsd, and a quick solution is to include the following code when launching the server:
-Djava.rmi.server.hostname=YOUR_SERVERS_IP
that fixes everything.
another problem im getting now has to do with BufferedImage. apperantly BufferedImage requires a screen to draw its image on. and i dont have one, when i shell into the system. i get this error:
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
Solution will be presented when i find it.
i got this on the client:
RMI connection refused problem solved.
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
when i was connecting to the bsd server which isnt localhost by the way, the error seems to stem from the way i have my hosts file setup on bsd, and a quick solution is to include the following code when launching the server:
-Djava.rmi.server.hostname=YOUR_SERVERS_IP
that fixes everything.
another problem im getting now has to do with BufferedImage. apperantly BufferedImage requires a screen to draw its image on. and i dont have one, when i shell into the system. i get this error:
java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
Solution will be presented when i find it.
RMI is pretty evil
new problems and their solutions:
any time you get an exception having to do with marshaling and you know that you have not changed any of your stubs, then its a codebase error! to fix:
System.setProperty("java.rmi.server.codebase","http://website.com/codebase/");
into that directory you can put your stubs, tho there is a little catch there. you have to put them in like this
http://website.com/codebase/package1/subpackage/Class_Impl_Stub.class
if the fully qualified name ofr Class_Impl_Stub is package1.subpackage.Class_Impl_Stub
people on the interweb say that using an http address is less troublesome then trying to use a file:// url
also, put your policy file into the same directory as your main jar file.
here is a good command line example of how i start my server:
>rmiregistry&
>java -Djava.rmi.server.hostname=134.88.14.133 -Djava.rmi.server.codebase=http://website.com/mk/codebase/ -Djava.security.policy=./policy.all -jar server.jar
note that server.jar contains a manifest file that points to all the libs it needs.
your client app should also have this codebase declaired obviously.
any time you get an exception having to do with marshaling and you know that you have not changed any of your stubs, then its a codebase error! to fix:
System.setProperty("java.rmi.server.codebase","http://website.com/codebase/");
into that directory you can put your stubs, tho there is a little catch there. you have to put them in like this
http://website.com/codebase/package1/subpackage/Class_Impl_Stub.class
if the fully qualified name ofr Class_Impl_Stub is package1.subpackage.Class_Impl_Stub
people on the interweb say that using an http address is less troublesome then trying to use a file:// url
also, put your policy file into the same directory as your main jar file.
here is a good command line example of how i start my server:
>rmiregistry&
>java -Djava.rmi.server.hostname=134.88.14.133 -Djava.rmi.server.codebase=http://website.com/mk/codebase/ -Djava.security.policy=./policy.all -jar server.jar
note that server.jar contains a manifest file that points to all the libs it needs.
your client app should also have this codebase declaired obviously.
Thursday, January 12, 2006
Serializing a Stream
We start by declaring _actualDocument to be transient. transient is a Java keyword that
tells the serialization mechanism not to serialize the variable's value out. We then implement
writeObject( ), which does two things:
· Calls out.defaultWriteObject( ). This invokes the generic serialization
mechanism (which is the default) to write out all nontransient objects. That is, when
out.defaultWriteObject( ) is called, everything but _actualDocument has been
encoded in the stream.
· Copies _actualDocument to the stream, exactly as we did for the socket-based version
of the program.
Similarly, in readObject( ), we first call defaultReadObject( ), which retrieves all the
nontransient values, including _length, from the stream. We then read _actualDocument
from the stream.
RMI Headaches part 2
Well some things have been figured out since yesterday they are:
- rmic takes package arguments as: rmic the.package.it.is.in.ClassName (so '.'s not '/')
- RMI treats classes that implements Serialazable as objects that are passed by value, so if you pass one of those objects to a server, dont expect local changes (i think?)
- RMI treas classes that extend Remote as objects to be passed by ref
- There is an Oreilly book on Java RMI that is good.
- rmic takes package arguments as: rmic the.package.it.is.in.ClassName (so '.'s not '/')
- RMI treats classes that implements Serialazable as objects that are passed by value, so if you pass one of those objects to a server, dont expect local changes (i think?)
- RMI treas classes that extend Remote as objects to be passed by ref
- There is an Oreilly book on Java RMI that is good.
Wednesday, January 11, 2006
Java RMI Headaches
Things one needs to do to get RMI working:
- Everything on the server must be interfaced where where interface extends Remote
- Everything that is passed between server and client must implement Serializable
- Every remote method must throw RemoteException
- You must run rmiregistry.exe on the server
- you cant use LocateRegistry on remote, must use Naming
- If you get a ClassNotFoundException on server it means you havent set your codebase properly.
- Since i havent figured out how to do SecurityManager stuff properly, i can override 2 checkPermission methods in SecurityManager with empty method bodies, thats a quick and dirty fix.
- Alternativly, you can set your policy file located in/lib/security/java.policy to: http://java.sun.com/docs/books/tutorial/rmi/example-1dot2/java.policy
RMI codebase crap:
Apperantly this needs to be set to something all clients can access, so a url on the www must be what this needs.
1. first you must compile your classes into stubs and skelletons with rmic.
- add rmic to your PATH variable in windows so you can use it. reopen all shells!
- or if windows decides to be gay and STILL NOT WORK, move the file to C:\windows
- at this point you should run rmic on your classes, so:
>rmic package/subpackage/ClassName
i get this error:
java.lang.NoClassDefFoundError
Google recomends:
Sometimes the rmic compiler has problems when the runtime libraries aren't
specified in the classpath. You shouldn't have to do this, but for some
reason it works. Try the following:
rmic -classpath;\jre\lib\rt.jar
ex: rmic -classpath C:\MyClasses;C:\java\jre\lib\rt.jar MyRMIObject
----
did that, still no go. Found this tho:
- eclipse RMI plugin that supports automatic stub/skel generation
http://www.genady.net/rmi/
example:
- Everything on the server must be interfaced where where interface extends Remote
- Everything that is passed between server and client must implement Serializable
- Every remote method must throw RemoteException
- You must run rmiregistry.exe on the server
- you cant use LocateRegistry on remote, must use Naming
- If you get a ClassNotFoundException on server it means you havent set your codebase properly.
- Since i havent figured out how to do SecurityManager stuff properly, i can override 2 checkPermission methods in SecurityManager with empty method bodies, thats a quick and dirty fix.
- Alternativly, you can set your policy file located in
RMI codebase crap:
Apperantly this needs to be set to something all clients can access, so a url on the www must be what this needs.
1. first you must compile your classes into stubs and skelletons with rmic.
- add rmic to your PATH variable in windows so you can use it. reopen all shells!
- or if windows decides to be gay and STILL NOT WORK, move the file to C:\windows
- at this point you should run rmic on your classes, so:
>rmic package/subpackage/ClassName
i get this error:
java.lang.NoClassDefFoundError
Google recomends:
Sometimes the rmic compiler has problems when the runtime libraries aren't
specified in the classpath. You shouldn't have to do this, but for some
reason it works. Try the following:
rmic -classpath
ex: rmic -classpath C:\MyClasses;C:\java\jre\lib\rt.jar MyRMIObject
----
did that, still no go. Found this tho:
- eclipse RMI plugin that supports automatic stub/skel generation
http://www.genady.net/rmi/
example:
Monday, January 09, 2006
Subscribe to:
Posts (Atom)