C++ for Python Programmers
by ventrix on Jan.08, 2009, under c/c++, python
C++ for Python Programmers
http://web.cse.msu.edu/~cse231/python2Cpp.html
Java float problems
by ventrix on Dec.23, 2008, under android, j2ee, j2se, java
If you want 0.6917 - 0.6911 to be 0.0006 then:
http://www.velocityreviews.com/forums/showpost.php?s=bfd8bcba71b3b530733952c65e86772a&p=1604265&postcount=4
There are three solutions:
1. If you’ve got enough accuracy but just need the numbers to look
better when you display them, then you can simply use
java.text.DecimalFormat to format the answers to a more reasonable
length when they are displayed. Rounding will occur as appropriate in
the display layer, and the result should look just fine.
2. If you aren’t getting enough precision, then you could look into the
double data type instead of float. Double has not only an immensely
larger range, but also approximately twice the precision in digits.
3. If you need exact math in decimal (often required for financial
calculations, for example) then the class java.math.BigDecimal is what
you’re looking for. BigDecimal lets you store values of any arbitrary
precision; it stores them in decimal, so you need not worry about
rounding that results from binary conversion, and you can customize the
rounding mode on operations that still need it, like division… or even
disabling rounding entirely so that the runtime will throw an exception
to let you know when a calculation won’t have an exact result.
Closing a stream
by ventrix on Dec.10, 2008, under android, j2ee, j2me, j2se, java
/**
* Closes the specified stream.
*
* @param stream The stream to close.
*/
private static void closeStream(Closeable stream) {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
android.util.Log.e("IO", "Could not close stream", e);
}
}
Use it like: closeStream(in);
Copy the content of the input stream into the output stream
by ventrix on Dec.10, 2008, under android, j2ee, j2me, j2se, java
Copy the content of the input stream into the output stream
/**
* Copy the content of the input stream into the output stream, using a temporary
* byte array buffer whose size is defined by {@link #IO_BUFFER_SIZE}.
*
* @param in The input stream to copy from.
* @param out The output stream to copy to.
*
* @throws IOException If any error occurs during the copy.
*/
private static final int IO_BUFFER_SIZE = 4 * 1024;
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] b = new byte[IO_BUFFER_SIZE];
int read;
while ((read = in.read(b)) != -1) {
out.write(b, 0, read);
}
}
Java Form Cracker Testing call
by ventrix on Nov.26, 2008, under j2se, java
Έφτιαξα μια εφαρμογή σε Java (brute forcer) που κάνει crack web forms.
Είναι αποτέλεσμα δουλειάς 3 ημερών και για αυτό χρειάζεται περαιτέρω testing.
Ο πηγαίος κώδικας θα δημοσιευτεί σύντομα.
Κατεβάστε το, δοκιμάστε το (θα βρείτε οδηγίες για να το δοκιμάσετε στον δικό μου server ελεύθερα) και στείλτε μου σχόλια!
Website: http://ventrix.nsdc.gr/projects/form_cracker/
(ΥΓ, δεν έχω ευθύνη για οτιδήποτε μπορεί να κάνετε με αυτό το εργαλείο, χρησιμοποιείστε το με δική σας ευθύνη)
Σχολιάστε ελεύθερα εδώ…
Creating random numbers in j2me and android within specific space
by ventrix on Nov.23, 2008, under Uncategorized, android, j2me, java
Creating random numbers in j2me within specific space
import java.util.Random;
/**
* Random Number Generator within specific space
* @param min is the minimum number to be produced
* @param max is the maximum number to be produced
* @return the random number
* @author ventrix
*/
public final class RandomCreator{
public static int getRandomInt(int min,int max)
{
try {
//Give the currentTimeMillis some time for the seed
Thread.sleep(2);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
Random randomizer = new Random(System.currentTimeMillis());
return randomizer.nextInt(max-min+1)+min;
}
}
Use it as: System.out.println(RandomCreator.getRandomInt(5,10));
Playing sound on Android Emulator
by ventrix on Nov.14, 2008, under android
The code is very simple and works perfectly, but nothing cames out of my speakers.
package gr.androiddev.test;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
public class SoundTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("aloha1");
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("http://ventrix.nsdc.gr/stuff/TERMITES_SKONH.mp3");
mp.prepare();
mp.start();
System.out.println("aloha2");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
To be able to hear sound on your Android Emulator on Linux, you must go to the “Run configuration, find the field named “Addition Emulator Command Line Options” and append the “-audio oss” option.
JSR180 SIP API for J2ME javadoc documentation
by ventrix on Oct.26, 2008, under j2me, java
Ok, I have found the javadoc on the internet, but I want to have it at my own server.
So, here it is: JSR180 SIP API
Jain-Sip javadoc Documentation
by ventrix on Oct.25, 2008, under j2ee, java
I’m currently working with Jain-Sip and the java doc site is down. So I uploaded it here.
You can download it for offline use here
PHP function for listing files with filesize
by ventrix on Oct.21, 2008, under php
function list_files($dir)
{
if(is_dir($dir))
{
if($handle = opendir($dir))
{
echo "
| Filename | Size |
| " .$file ." | " .filesize($file)/1024 ." kB | \n"; } echo "
Use it as the following:
list_files(”/home/test/files”);