Sunday, November 8, 2015

OKCupid: Automatic Search and Message Script

Are you tired of copy/paste method you do on OKCupid to get more girls respond to you? Let's be honest here, we can hardly get around 20 girls replying to us a day and chances are you don't really like them. 

With this script I made for OKCupid, you don't need to copy/paste anymore! Just set it up for in less than a minute, hit click, and do your other businesses while the script do the work for you.

What Do I Need?

1. You need Mozilla Firefox (latest version)
2. Good internet speed
3. iMacro Plugin download it here.

Finally, get the script on my Fiverr Gig:
https://www.fiverr.com/neutt22/give-my-okcupid-automatic-search-message-script-ffb7a5ea-3efe-434c-8530-22e8ec08d3b9

Approximately, the script can send 100+ messages per minute.

Included in the package is the script for the browser and a very simple VIDEO instruction on how to get it running.

Please share us your experience with this script.

Thanks

Thursday, October 8, 2015

Basic SQL Operations Using Java


Today's post, we are going to see how to make an application that interacts with a database. We will learn how to CREATE, READ, UPDATE, and DELETE rows on MySQL the database application we are going to use. 


  • CREATE operation creates a new row to the specified table. This operation is being used to register a new account to a website. 
  • READ operation returns rows from the specified table. This is mostly used to retrieve information searched by the user.
  • UPDATE operation updates certain numbers of row to the table. Programmers use this operation to edit an information. Example usage is updating the member's last name and age.
  • DELETE operation deletes a row from a table. Usage included account deactivation.

For our future tutorials, we will be creating a database with tables we're going to feed it with a dummy information. But for now, we will see a very basic structure of a database table:

Table Name: members

| ID | first_name | last_name | age |
-----------------------------------------
| 1  | John          |  Collin       | 24   |
-----------------------------------------
| 2  | Peter         | Guy          | 24   |
-----------------------------------------
| 3  | Brook        | Hill           | 13   |
-----------------------------------------
| 4  | James        | Duff         | 12   |
-----------------------------------------

How to search using SELECT SQL operation: Prints all members that has an age of 24.


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Searcher{

public static void search(int age){
  try{
   Class.forName("com.mysql.jdbc.Driver");
   Connection connect = DriverManager.getConnection(CONNECTION);
   Statement statement = connect.prepareStatement("SELECT * from members where age=?");
   statement.setInt(1, age);
   ResultSet resultSet = statement.executeQuery();
   
   while(resultSet.next()){
    System.out.println("Name: " + resultSet.getString("name");
   }
   connect.close();
   statement.close();
   resultSet.close();
  }catch(Exception e){
   e.printStackTrace();
  }
}

 public static void main(String args[]){
                System.out.println("Members with age 24");
  Searcher.search(24); //we want to print all members with age 24.
 }
}

How to create row using CREATE SQL operation: Adds member to a members table.



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Adder{

 public void addMember(String first_name, String last_name, int age){
  try{
   Class.forName("com.mysql.jdbc.Driver");
   connect = DriverManager.getConnection(CONNECTION);
   statement = connect.prepareStatement("INSERT INTO members (first_name, last_name, age) VALUES (?,?,?)");
   statement.setString(1, first_name);
   statement.setString(2, last_name);
   statement.setInt(3, age);
   statement.executeUpdate();
   connect.close();
   statement.close();
  }catch(Exception e){
   e.printStackTrace();
  }
 }

 public static void main(String args[]){
  Adder.addMember("Jonas", "Robinso", 25);
                System.out.println("A member has been added!");
 }
}

How to update row using UPDATE SQL operation: Edits member to a members table.



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Updater{

 public void update(String first_name){
  try{
   Class.forName("com.mysql.jdbc.Driver");
   connect = DriverManager.getConnection(CONNECTION);
   statement = connect.prepareStatement("UPDATE members SET age=" + 25 + " WHERE first_nam='" + first_name + "'");
   statement.executeUpdate();
   connect.close();
   statement.close();
  }catch(Exception e){
   e.printStackTrace();
  }
 }

 public static void main(String args[]){
  Updater.update("Brook");
 }
}

How to delete a row using DELETE SQL operation: Deletes a member from a table.



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Deleter{

 public void delete(String first_name){
  try{
   Class.forName("com.mysql.jdbc.Driver");
   connect = DriverManager.getConnection(CONNECTION);
   statement = connect.prepareStatement("DELETE from members where first_name='" + first_name + "'");
   statement.executeUpdate();
   connect.close();
   statement.close();
  }catch(Exception e){
   e.printStackTrace();
  }
 }

 public static void main(String args[]){
  Deleter.delete("Brook");
 }
}


It is strongly recommended to run these classes on your favorite Java IDE like and play around until you get the hang of it and make a cool ideas for your next Java application :)

Friday, December 6, 2013

Google GSON - Example Usage In Java

If you're a Java Developer like me then I'm certainly sure that you have heard about Google's GSON. Well, it's develop to provide a simple yet efficient way to create JSON in Java. JSON means Javascript Object Notation. It is a data interchange which is same as the old XML.

In this tutorial, we are going to implement Google's GSON to our Java application. First, you need to create a simple class that JSON data can represent:



import java.util.ArrayList;
import java.util.List;



public class MyData{
 
 public String message = "Hello, World!";
 private List messages = new ArrayList(){
  {
   add("Message for friends");
   add("Message for family");
   add("Message for girlfriends");
   add("Message for strangers");
  }
 };
 
 public String toString(){
  return "MyData[message=" + message + ", messages=" + messages + "]";
 }
}
It represents our JSON data. So now we want to convert this object into JSON format. How should we do that? Please copy & paste the example below:

import java.io.FileWriter;
import java.io.IOException;
import com.google.gson.Gson;
 
public class Main {
    public static void main(String[] args) {
 
 MyData obj = new MyData();
 Gson gson = new Gson();
 String json = gson.toJson(obj);
 try {
  FileWriter writer = new FileWriter("C:\\data.json");
  writer.write(json);
  writer.close();
 } catch (IOException e) {
  e.printStackTrace();
 }
 System.out.println("JSON:" + json);
 
    }
}
The trick here is to call the Gson class' toJson method. It will going to return the JSON encoded object as String. Very handy! Now the next lines are just the method to save it to a file called "data.json". Do not forget to close your resources to free up some memories.

Now that you have already your json file, you probably want it to send over the network. You need now to convert the JSON encoded format back to a simple java object. Here's the code for that:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import com.google.gson.Gson;
 
public class Main {
    public static void main(String[] args) {
  Gson gson = new Gson();
  try {
   BufferedReader br = new BufferedReader( new FileReader("C:\\data.json"));
   MyData data = gson.fromJson(br, MyData.class);
   System.out.println(data);
  
  } catch (IOException e) {
   e.printStackTrace();
  }
    }
}

Play around this wonderful library by Google and I'm sure in one day you will get the hang of it! Easy right?
Thanks for reading all my stuff here in Geek Stuff!

Save Object State - How To Use Java Serialization

Object serialization in Java is one of the advanced topic in Java. In this tutorial, I'm going to show you the basic on how to serialize a simple object and then deserialize it later.

First, you want to create a simple object in which you wanted to be serialized. By the way, when I say serialize, Java will store the "state" of the particular object in bytes like saving it into a file.

Please copy & paste the source code below:

public class Hero {
 
 private int energy, life, locationx, locationy = 0;

 public Hero(){
  
 }
 
 public void setEnergy(int e){
  energy = e;
 }
 
 public void setLife(int l){
  life = l;
 }
 
 public void setLocation(int x, int y){
  locationx = x;
  locationy= y;
 }
 
 public int getLocationX() { return locationx; }
 public int getLocationY() { return locationy; }
 public int getLife() { return life; }
 public int getEnergy() { return energy; }

}

Our hero class will be serialize by creating an instance of it and using the ObjectOutputStream bundled in the Java foundation class. See example below to change the state of the Hero class and save it to a file called "hero.dat":

public class Main {
 
 public static void main(String args[]){
  Hero hero = new Hero();
  hero.setLife(100);
  hero.setEnergy(99);
  hero.setLocation(1,1);
  
  try {
         FileOutputStream fOut = new FileOutputStream("C:\\hero.dat");
         ObjectOutputStream oOut = new ObjectOutputStream(fOut);
         oOut.writeObject(e);
         oOut.close();
         fOut.close();
         System.out.printf("Success! Object has been saved.");
     }catch(Exception e){
           e.printStackTrace();
     }
 }
}
Now check out your C:\ directory and most certainly you will find a file named hero.dat which our Hero object has been stored and saved.


Now you wanted to "load" the state of our Hero class back to your application probably because you wanted to change the state. This is where the ObjectInputStream class comes into play. To deserialize our object, please run this example code given below:


public class Main {
 
 public static void main(String args[]){
  Hero hero = null;
  
  
  try {
         FileInputStream fIn = new FileInputStream("C:\\hero.dat");
         ObjectInputStream oIn = new ObjectInputStream(fIn);
         hero = (Hero) oIn.readObject();
         fIn.close();
         oIn.close();
         System.out.printf("Success! Object has been restored.");
     }catch(Exception e){
           e.printStackTrace();
     }
     
     System.out.println("Hero Life: " + hero.getLife());
     System.out.println("Hero Energy: " + hero.getEnergy());
     System.out.println("Hero X: " + hero.getLocationX());
     System.out.println("Hero Y: " + hero.getLocationY());
 }
}

Voila! You just made your first Java serialization/deserialization tutorial. I hope you enjoyed my post and thank you for reading my tutorials. Please comment below if you have some questions regarding this post.
Have a nice day!

Wednesday, December 4, 2013

Protect Your Documents - Use Jasypt For Java

Do you have that one family member who always messes up with your documents on your computer? Well, if you're looking for a library in Java, you can give a try to Jasypt. I always use this library in every of my projects because not only it is super easy to implement and use but many of Developers are now using this wonderful library. Give it a try! Download it now!

I use this library mostly when I make apps that need an internet connection. Because we have no idea that someone is intercepting our communication and stealing our data. This is what we called Man-in-the-middle attack. You can google about that type of attack over the network.
But with the help of Jasypt, the chance of being MiM the network gets slimmer. Just take this example, please make a new project with new class and copy paste this code:

public class Main {
 public static void main(String arg){
  BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
  textEncryptor.setPassword("MySecretPasswordOnlyTrustedFriendsKnow");
  String myEncryptedText = textEncryptor.encrypt("MySecretMessageToMyFriends");
 }
}

And on the machine that receive the message, he needs to decrypt the message using the same password used to encrypt it.

textEncryptor.setPassword("MySecretPasswordOnlyTrustedFriendsKnow");
textEncryptor.decrypt(myEncryptedText);
Just toy around to that easy-to-use security library and in no time you will get the hang of it.
Having a good security to your application is vital.
Thanks for reading!

How To Use Apache Log4j In Your Java Application

Hi guys, being able to log what your applications behave since its first released or under development is one of the great things you need to consider being a Developer. So in this tutorial, I'm going to show you the basic on how to install Apache Log4j to your own java application.

First, download the library and create a new project in Eclipse then add the log4j to your classpath.
Make a new class by right clicking the src folder and select New > Class and name your class an appropriate name.

In log4j, there are a lot of levels, namely:

  1. DEBUG
  2. ERROR
  3. FATAL
  4. INFO
  5. TRACE
  6. WARN
Now copy and paste this code:

import org.apache.log4j.Logger;
public class MyLogger{
   private static Logger log = Logger.getLogger(LogClass.class);
   public static void main(String[] args) {
      log.trace("Trace Message..");
      log.debug("Debug Message..");
      log.info("Info Message..");
      log.warn("Warn Message..");
      log.error("Error Message..");
      log.fatal("Fatal Message..");
   }
}
Output:
Debug Message..
Info Message..
Warn Message..
Error Message..
Fatal Message..
Depending on how crucial the application is executing you will use the right level for your application.
Say for example, your application is trying to write to a file but it there's not enough permission, you can then log it and be like:
ERROR: Unable to write to a file: 'C:\updates.json'
That's it! I hope you learned something new about this wonderful library! Thanks for reading guys. If you have questions then feel free to contact me or post your problems here regarding this library.

How To Use Ini4j To Your Java Application

You can use ini4j to your project to make some changes on your application settings even without recompiling it. The ini4j tutorial can make you up and running using this library as well.

The first thing we want to do is to download the library and integrate it with our favorite IDE. I recommend Eclipse IDE as you can easily add up additional libraries on your project without getting any trouble.


Simple Windows .ini file

This will be our very simple .ini file we are using throughout this tutorial. Please copy/paste this to your empty config/settings.ini file.

[main]
window-color = 00ffff
splash = true
[others]
version = 0.1
developer = Jim

Reading from .ini file


import java.io.File;
import java.io.IOException;

import org.ini4j.InvalidFileFormatException;
import org.ini4j.Wini;


public class Main {
 
 public static void main(String args[]){
  try{
   Wini ini;
   /* Load the ini file. */
   ini = new Wini(new File("config/settings.ini"));
   /* Extract the window color value.*/
   int windowColor = ini.get("main", "window-color", int.class);
   /* Extract the splash screen status. */
   boolean splashScreen = ini.get("main", "splash", boolean.class);
   
   /* Show to user the output. */
   System.out.println("Your default window color is: " + windowColor);
   if(splashScreen){
    System.out.println("You have your splash screen activated.");
   }else{
    System.out.println("You have your splash disabled.");
   }
  } catch (InvalidFileFormatException e) {
   System.out.println("Invalid file format.");
  } catch (IOException e) {
   System.out.println("Problem reading file.");
  }
 }
The code above is pretty self explanatory and you could easly guess what the line of code does just by looking at it. We just basically read the settings.ini file from config directory and parse the windowColor value and splashScreen status to show to user.

Writing to windows .ini file


import java.io.File;
import java.io.IOException;

import org.ini4j.InvalidFileFormatException;
import org.ini4j.Wini;


public class Main {
 
 public static void main(String args[]){
 Wini ini;
 try {
  ini = new Wini(new File("config/settings.ini"));
  ini.put("main", "window-color", 000000);
  ini.put("main", "splash", false);
  ini.store();
 } catch (InvalidFileFormatException e) {
  System.out.println("Invalid file format.");
 } catch (IOException e) {
  System.out.println("Problem reading file.");
 }
  
 }
The code above couldn't get any simpler. We are basically overwriting the value of window-color and splash in main section. Then we invoke the Wini.store() method to update our ini file.

This simple tutorial can make you up and running using this wonderful library. Thank you for reading, have a nice day everybody!