Skip to content

Commit

Permalink
add scripts to produce the captcha images
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoweibin committed Dec 12, 2011
1 parent 1d8eb03 commit 5f02bd7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
35 changes: 35 additions & 0 deletions captcha/Captcha.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import java.io.File;
import java.util.Random;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

class Captcha {

public static String getRandomString(int length) {

String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random = new Random();
StringBuffer sb = new StringBuffer();

for (int i = 0; i < length; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}

return sb.toString();
}

public static void main(String args[]) throws java.io.IOException {

ImageCaptchaGenerator gen = new ImageCaptchaGenerator();

for (int i = 0; i < 10000; i++) {
String word = getRandomString(7);
BufferedImage bi = gen.getImage(word);
String filename = word + ".jpg";
File out = new File(filename);
ImageIO.write(bi, "jpg", out);
}
}
}
Binary file added captcha/combined.jar
Binary file not shown.
14 changes: 14 additions & 0 deletions captcha/get_img.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

require 'memcached'

$cache = Memcached.new("localhost:11211")

i = 10000
until i == 0 do
key = $cache.get(i.to_s, false)
value = $cache.get(key, false)
puts "#{i}, #{key}, #{value.length}"

i = i - 1;
end

2 changes: 2 additions & 0 deletions captcha/makeimg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
javac -cp .:combined.jar Captcha.java
java -cp .:combined.jar Captcha
16 changes: 16 additions & 0 deletions captcha/put_img.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

require 'memcached'

#pipelined, good for write
$cache = Memcached.new("localhost:11211", :no_block => true, :buffer_requests => true, :noreply => true, :binary_protocol => false)

i = 0
Dir.glob("./img/*.jpg") do |f|
i = i + 1;
key = f.match(/([a-zA-Z]+)\.jpg/)[1]
value = File.read(f)
$cache.set(i.to_s, key, 0, false)
$cache.set(key, value, 0, false)
end

puts "Total records: #{i}"

0 comments on commit 5f02bd7

Please sign in to comment.