Friday, June 15, 2012

Remote, Client-side Validation ASP.NET MVC 3

ASP.NET MVC allows one to provide remote clientside validation. In this example on GitHub, in the validation controller, I add validation for the username and email. Also, this uses the default membership class, so it is more compatible.

Remember to fill in your first and last name so the client validation can work.
It will first try [FIRSTNAME].[LASTNAME] If that also is taken, it will display [USERNAME][LOWEST INTEGER POSSIBLE]
Affected fields:
-username
-email



Find it here: https://github.com/arithehun/MVC-Remote-Validation-Intelligence-

Read more awesomeness from Ari Falkner >

Thursday, June 14, 2012

How to Talk Like a Girl


Facebook revolutionized communication. Skype is much more private,
but with Facebook, it was not uncommon to have a conversation with a female.
I began to notice that females chat very interestingly. They will elongate
words, litter their phrases with smily faces and assume peppy personalities.
(DISCLAIMER: This does not at all correspond to all girls)
I began to go on to forums to see what was going on. I was able to find no definite,
prevailing answer, but I did discover two likely scenarios: either they liked you (in which
case I would be in good luck), but I leaned towards the more probable answer that it was their
chosen method of discourse.
Whatever the case, I decided to take about 45 minutes out of my first day on summer break to make this. Enjoy!


girltalk.apphb.com

Read more awesomeness from Ari Falkner >

Saturday, April 21, 2012

Get Hexadecimal Code of a Bitmap

Many of us in writing C code for machines needed to interpret hexadecimal arrays to bitmaps. But it can get extremely tiresome and tedious manually copying each bit and THEN converting it to hex. Well lucky for you, I created a program that does it for you. You can even invert the bits.

Why choose Bitmap Ex-celerate Converter?


  • It's flagship feature is that it ignores the padding 0 byte automatically for you, leaving you with a clean array. It can take bitmaps of any sizes, and even formats the code for you. Beautiful!
  • No padding -- simply displays the width and height in a hexadecimal for the first 2 bytes of the array and then just starts the array. 
  • Easy deploy -- after generating, just go to File > Save..., and change the extension from .bmp to .h and then save. Open it up in a text-editor in you'll see how nice it looks!
  • Easy access editing -- edit before saving
  • FREE
NOTE: in the in program editor, the rows will not look aligned. This is because the font does not grant equal pixels per character. Open it up in something like Notepad++ after saving it in .h form, and you'll see how aligned they are.

You're welcome.

Get it here: j.mp/ex-celerate

Read more awesomeness from Ari Falkner >

Monday, April 2, 2012

Download (Part of) an Image Database (Zuckerberg-style!)

We all remember from the movie The Social Network how Mark used simple scripts to download the entire catalog of student directory posts. I will show you how to do the same in Java.

Requirements:

  • A text editor (Notepad or Notepad++ will do)
  • A Mac with Terminal
  • Basic Java knowledge

Procedure

How this program will work is it will basically be for downloading a large succession of images from a database. The database will often have a template such as www.example.com/folderone/foldertwo/folderthree/J8031736345854221.JPG, with the next picture being J8031736345854222.JPG. The program will increment the last digit by 1 through a specified range.

Step 1:

First, in the Java editor, we add the basic configuration code to a file you created titled "Main.java":

import java.lang.Runtime;
import java.io.IOException;
import javax.swing.JOptionPane;
import java.lang.Integer;
import java.lang.String;

public class Main {
 public static void main(String[] args) {
        }
}

You should probably be able to tell the classes we will be using.

Step 2:

Let's say we want www.example.com/folderone/foldertwo/folderthree/J8031736345854221.JPG through www.example.com/folderone/foldertwo/folderthree/J8031736345854353.JPG
Now, we display three dialogue boxes asking for a string. Basically, the first box will take in the left unchanging part of the URL (www.example.com/folderone/foldertwo/folderthree/J8031736345854, for example), the second asking for the range of the variable part (221-353), and the last asking for the unchanging ending (.JPG). 

        String firstURL = JOptionPane
    .showInputDialog(null,
      "Enter the first part of the static URL",
      "http://www.example.com/firstFolder/SecondFolder/firstpartoffiles");

  String secondURL = JOptionPane.showInputDialog(null,
    "Enter the variable part of the URL in a range", "x-y");

  String thirdURL = JOptionPane.showInputDialog(null,
    "Enter the first part of the static URL", ".jpg");

Step 3:

Now, we need to split the range into an array of values at the dash
String[] range = secondURL.split("-");

Step 4:

Finally, we need to add a loop downloading the image using the Unix wget command, then update the changing part, then download it again (we also add some logs to the terminal for fun):

for (int i = Integer.parseInt(range[0]); i <= Integer.parseInt(range[1]); i++) {
   try {
    
    System.out.println("wget " + firstURL + i + thirdURL);
    Process p = r.exec("wget "+ firstURL + i + thirdURL);

    
   } catch (IOException e) {
    e.printStackTrace();
   }

Reconciliation:

If you were following along so far, you're code should look like this:

import java.lang.Runtime;
import java.io.IOException;
import javax.swing.JOptionPane;
import java.lang.Integer;
import java.lang.String;

public class Main {
 public static void main(String[] args) {

  String firstURL = JOptionPane
    .showInputDialog(null,
      "Enter the first part of the static URL",
      "http://www.example.com/firstFolder/SecondFolder/firstpartoffiles");

  String secondURL = JOptionPane.showInputDialog(null,
    "Enter the variable part of the URL in a range", "x-y");

  String thirdURL = JOptionPane.showInputDialog(null,
    "Enter the first part of the static URL", ".jpg");

  
  String[] range = secondURL.split("-");
  
  Runtime r = Runtime.getRuntime();
  
  
  for (int i = Integer.parseInt(range[0]); i <= Integer.parseInt(range[1]); i++) {
   try {
    
    System.out.println("wget " + firstURL + i + thirdURL);
    Process p = r.exec("wget "+ firstURL + i + thirdURL);

    
   } catch (IOException e) {
    e.printStackTrace();
   }
  }

 }
}

Running the application

Move the Java file (Main.java) into the folder you wish to download the images into.

Now open Terminal and type to navigate to the file location:
cd (then the directory you placed Main.java into)

Now, compile the program by typing:

javac Main.java

Finally, run the program by typing:

java Main



Now, just enter in the information into the dialogue boxes, in the range one separating your values by a hyphen. Once in process, the System.out.println statement kicks in, printing the web addresses of each downloaded image so you can see that everything is working all right.

Please subscribe for more tips.

Read more awesomeness from Ari Falkner >