-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scripts to produce the captcha images
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |