flatulent 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/flatulent-0.0.4.gem +0 -0
  2. data/install.rb +210 -0
  3. data/lib/flatulent.rb +76 -61
  4. data/rails/app/controllers/flatulent_controller.rb +6 -4
  5. data/rails/log/development.log +7242 -0
  6. data/rails/tmp/sessions/ruby_sess.82080df62364f531 +0 -0
  7. data/rails/tmp/sessions/ruby_sess.8900d08ad306f253 +0 -0
  8. data/rails/tmp/sessions/ruby_sess.f8fa47c3571d2497 +0 -0
  9. metadata +7 -49
  10. data/flatulent-0.0.2.gem +0 -0
  11. data/rails/lib/flatulent.rb +0 -450
  12. data/rails/lib/flatulent/attributes.rb +0 -79
  13. data/rails/lib/flatulent/crypt/blowfish-tables.rb +0 -190
  14. data/rails/lib/flatulent/crypt/blowfish.rb +0 -109
  15. data/rails/lib/flatulent/crypt/cbc.rb +0 -123
  16. data/rails/lib/flatulent/crypt/gost.rb +0 -140
  17. data/rails/lib/flatulent/crypt/idea.rb +0 -193
  18. data/rails/lib/flatulent/crypt/noise.rb +0 -94
  19. data/rails/lib/flatulent/crypt/purerubystringio.rb +0 -378
  20. data/rails/lib/flatulent/crypt/rijndael-tables.rb +0 -117
  21. data/rails/lib/flatulent/crypt/rijndael.rb +0 -269
  22. data/rails/lib/flatulent/fontfiles/banner.flf +0 -2494
  23. data/rails/lib/flatulent/fontfiles/big.flf +0 -2204
  24. data/rails/lib/flatulent/fontfiles/block.flf +0 -1691
  25. data/rails/lib/flatulent/fontfiles/bubble.flf +0 -1630
  26. data/rails/lib/flatulent/fontfiles/digital.flf +0 -1286
  27. data/rails/lib/flatulent/fontfiles/ivrit.flf +0 -900
  28. data/rails/lib/flatulent/fontfiles/lean.flf +0 -1691
  29. data/rails/lib/flatulent/fontfiles/mini.flf +0 -899
  30. data/rails/lib/flatulent/fontfiles/mnemonic.flf +0 -3702
  31. data/rails/lib/flatulent/fontfiles/script.flf +0 -1493
  32. data/rails/lib/flatulent/fontfiles/shadow.flf +0 -1097
  33. data/rails/lib/flatulent/fontfiles/slant.flf +0 -1295
  34. data/rails/lib/flatulent/fontfiles/small.flf +0 -1097
  35. data/rails/lib/flatulent/fontfiles/smscript.flf +0 -1097
  36. data/rails/lib/flatulent/fontfiles/smshadow.flf +0 -899
  37. data/rails/lib/flatulent/fontfiles/smslant.flf +0 -1097
  38. data/rails/lib/flatulent/fontfiles/standard.flf +0 -2227
  39. data/rails/lib/flatulent/fontfiles/term.flf +0 -600
  40. data/rails/lib/flatulent/pervasives.rb +0 -32
  41. data/rails/lib/flatulent/stringxor.rb +0 -27
  42. data/rails/lib/flatulent/text.rb +0 -6
  43. data/rails/lib/flatulent/text/double_metaphone.rb +0 -356
  44. data/rails/lib/flatulent/text/figlet.rb +0 -17
  45. data/rails/lib/flatulent/text/figlet/font.rb +0 -117
  46. data/rails/lib/flatulent/text/figlet/smusher.rb +0 -64
  47. data/rails/lib/flatulent/text/figlet/typesetter.rb +0 -68
  48. data/rails/lib/flatulent/text/levenshtein.rb +0 -65
  49. data/rails/lib/flatulent/text/metaphone.rb +0 -97
  50. data/rails/lib/flatulent/text/porter_stemming.rb +0 -171
  51. data/rails/lib/flatulent/text/soundex.rb +0 -61
File without changes
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rbconfig'
3
+ require 'find'
4
+ require 'ftools'
5
+ require 'tempfile'
6
+ include Config
7
+
8
+ LIBDIR = "lib"
9
+ LIBDIR_MODE = 0644
10
+
11
+ BINDIR = "bin"
12
+ BINDIR_MODE = 0755
13
+
14
+
15
+ $srcdir = CONFIG["srcdir"]
16
+ $version = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
17
+ $libdir = File.join(CONFIG["libdir"], "ruby", $version)
18
+ $archdir = File.join($libdir, CONFIG["arch"])
19
+ $site_libdir = $:.find {|x| x =~ /site_ruby$/}
20
+ $bindir = CONFIG["bindir"] || CONFIG['BINDIR']
21
+ $ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
22
+ $ruby_ext = CONFIG['EXEEXT'] || ''
23
+ $ruby = File.join($bindir, ($ruby_install_name + $ruby_ext))
24
+
25
+ if !$site_libdir
26
+ $site_libdir = File.join($libdir, "site_ruby")
27
+ elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
28
+ $site_libdir = File.join($site_libdir, $version)
29
+ end
30
+
31
+ def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
32
+ #{{{
33
+ path = []
34
+ dir = []
35
+ Find.find(srcdir) do |f|
36
+ next unless FileTest.file?(f)
37
+ next if (f = f[srcdir.length+1..-1]) == nil
38
+ next if (/CVS$/ =~ File.dirname(f))
39
+ next if f =~ %r/\.lnk/
40
+ path.push f
41
+ dir |= [File.dirname(f)]
42
+ end
43
+ for f in dir
44
+ next if f == "."
45
+ next if f == "CVS"
46
+ File::makedirs(File.join(destdir, f))
47
+ end
48
+ for f in path
49
+ next if (/\~$/ =~ f)
50
+ next if (/^\./ =~ File.basename(f))
51
+ unless bin
52
+ File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
53
+ else
54
+ from = File.join(srcdir, f)
55
+ to = File.join(destdir, f)
56
+ shebangify(from) do |sf|
57
+ $deferr.print from, " -> ", File::catname(from, to), "\n"
58
+ $deferr.printf "chmod %04o %s\n", mode, to
59
+ File::install(sf, to, mode, false)
60
+ end
61
+ end
62
+ end
63
+ #}}}
64
+ end
65
+ def shebangify f
66
+ #{{{
67
+ open(f) do |fd|
68
+ buf = fd.read 42
69
+ if buf =~ %r/^\s*#\s*!.*ruby/o
70
+ ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
71
+ begin
72
+ fd.rewind
73
+ ftmp.puts "#!#{ $ruby }"
74
+ while((buf = fd.read(8192)))
75
+ ftmp.write buf
76
+ end
77
+ ftmp.close
78
+ yield ftmp.path
79
+ ensure
80
+ ftmp.close!
81
+ end
82
+ else
83
+ yield f
84
+ end
85
+ end
86
+ #}}}
87
+ end
88
+ def ARGV.switch
89
+ #{{{
90
+ return nil if self.empty?
91
+ arg = self.shift
92
+ return nil if arg == '--'
93
+ if arg =~ /^-(.)(.*)/
94
+ return arg if $1 == '-'
95
+ raise 'unknown switch "-"' if $2.index('-')
96
+ self.unshift "-#{$2}" if $2.size > 0
97
+ "-#{$1}"
98
+ else
99
+ self.unshift arg
100
+ nil
101
+ end
102
+ #}}}
103
+ end
104
+ def ARGV.req_arg
105
+ #{{{
106
+ self.shift || raise('missing argument')
107
+ #}}}
108
+ end
109
+ def linkify d, linked = []
110
+ #--{{{
111
+ if test ?d, d
112
+ versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
113
+ versioned.each do |v|
114
+ src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
115
+ lnk = nil
116
+ begin
117
+ if test ?l, dst
118
+ lnk = "#{ dst }.lnk"
119
+ puts "#{ dst } -> #{ lnk }"
120
+ File::rename dst, lnk
121
+ end
122
+ unless test ?e, dst
123
+ puts "#{ src } -> #{ dst }"
124
+ File::copy src, dst
125
+ linked << dst
126
+ end
127
+ ensure
128
+ if lnk
129
+ at_exit do
130
+ puts "#{ lnk } -> #{ dst }"
131
+ File::rename lnk, dst
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+ linked
138
+ #--}}}
139
+ end
140
+
141
+
142
+ #
143
+ # main program
144
+ #
145
+
146
+ libdir = $site_libdir
147
+ bindir = $bindir
148
+ no_linkify = false
149
+ linked = nil
150
+ help = false
151
+
152
+ usage = <<-usage
153
+ #{ File::basename $0 }
154
+ -d, --destdir <destdir>
155
+ -l, --libdir <libdir>
156
+ -b, --bindir <bindir>
157
+ -r, --ruby <ruby>
158
+ -n, --no_linkify
159
+ -s, --sudo
160
+ -h, --help
161
+ usage
162
+
163
+ begin
164
+ while switch = ARGV.switch
165
+ case switch
166
+ when '-d', '--destdir'
167
+ libdir = ARGV.req_arg
168
+ when '-l', '--libdir'
169
+ libdir = ARGV.req_arg
170
+ when '-b', '--bindir'
171
+ bindir = ARGV.req_arg
172
+ when '-r', '--ruby'
173
+ $ruby = ARGV.req_arg
174
+ when '-n', '--no_linkify'
175
+ no_linkify = true
176
+ when '-s', '--sudo'
177
+ sudo = 'sudo'
178
+ when '-h', '--help'
179
+ help = true
180
+ else
181
+ raise "unknown switch #{switch.dump}"
182
+ end
183
+ end
184
+ rescue
185
+ STDERR.puts $!.to_s
186
+ STDERR.puts usage
187
+ exit 1
188
+ end
189
+
190
+ if help
191
+ STDOUT.puts usage
192
+ exit
193
+ end
194
+
195
+ system "#{ sudo } #{ $ruby } pre-install.rb" if test(?s, 'pre-install.rb')
196
+
197
+ unless no_linkify
198
+ linked = linkify('lib') + linkify('bin')
199
+ end
200
+
201
+ system "#{ $ruby } extconf.rb && make && #{ sudo } make install" if test(?s, 'extconf.rb')
202
+
203
+ install_rb(LIBDIR, libdir, LIBDIR_MODE)
204
+ install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
205
+
206
+ if linked
207
+ linked.each{|path| File::rm_f path}
208
+ end
209
+
210
+ system "#{ sudo } #{ $ruby } post-install.rb" if test(?s, 'post-install.rb')
@@ -1,6 +1,5 @@
1
1
  class Flatulent
2
- Flatulent::VERSION = '0.0.3' unless defined? Flatulent::VERSION
3
- def self.flatulent() Flatulent::VERSION end
2
+ def self.version() '0.0.4' end
4
3
  def self.libdir() File.expand_path(__FILE__).gsub(%r/\.rb$/, '') end
5
4
 
6
5
  require 'cgi'
@@ -42,12 +41,13 @@ class Flatulent
42
41
  'font-weight' => 'bold',
43
42
  'font-size' => 'medium',
44
43
  #'background' => '#ffc',
45
- 'background' => '#ccffcc',
44
+ 'background' => '#ffff99',
46
45
  #'color' => '#000',
47
- 'color' => '#330066',
46
+ 'color' => '#000000',
48
47
  'margin' => '2px',
49
48
  'padding' => '2px',
50
49
  'display' => 'table',
50
+ 'width' => '33%',
51
51
  ] }
52
52
 
53
53
  attribute('key'){ default_key }
@@ -265,7 +265,8 @@ class Flatulent
265
265
  end
266
266
 
267
267
  @font = String opt[ 'font', 'big' ]
268
- @noise = Float opt[ 'noise', 0.22 ]
268
+ @noise = Float opt[ 'noise', 0.05 ]
269
+ @transform = Float opt[ 'transform', 0.03 ]
269
270
  @id = String opt[ 'id', 'flatulent' ]
270
271
  @action = String opt[ 'action' ]
271
272
  @ttl = Integer opt[ 'ttl', 300 ]
@@ -421,53 +422,69 @@ class Flatulent
421
422
  end #--}}}
422
423
 
423
424
  def captcha! #--{{{
424
- @captcha = " " * @figlet.size
425
+ figlet = @figlet.dup
426
+ chars = figlet.split %r""
427
+ hammer chars
428
+ figlet = chars.join
425
429
  space = " "[0]
426
430
  newline = "\n"[0]
427
- noisy = %w`| / - _ ( ) \\ ! [ ]`
428
431
 
429
- @figlet.size.times do |i|
430
- fbyte = @figlet[i]
432
+ @captcha = " " * figlet.size
433
+ # merge vapour with figlet
434
+ figlet.size.times do |i|
435
+ fbyte = figlet[i]
431
436
  vbyte = @vapour[i]
432
437
 
433
438
  if fbyte == newline
434
439
  @captcha[i] = newline
435
440
  elsif fbyte == space
436
- #if vbyte == space
437
- #@captcha[i] = noisy[ rand(noisy.size) ]
438
- #else
439
- @captcha[i] = vbyte
440
- #end
441
+ @captcha[i] = vbyte
441
442
  else
442
443
  @captcha[i] = fbyte
443
444
  end
444
445
  end
446
+ @captcha
447
+ end #--}}}
445
448
 
446
-
447
- =begin
448
- alpha = ('A'..'Z').to_a + ('a'..'z').to_a
449
+ def hammer chars #--{{{
450
+ # transform character chars
451
+ newline = "\n"[0]
452
+ space = " "[0]
453
+ alphas = ('A'..'Z').to_a + ('a'..'z').to_a
449
454
  transform = {
450
- '|' => rchar(%w'. * \` + , ; : '),
451
- '/' => rchar(%w'\\ ] [ { } ( ) @' + alpha),
452
- '\\' => rchar(%w'/ ] [ { } ( ) @' + alpha),
455
+ '|' => rchar(%w'. * + , ; : ' + alphas),
456
+ '/' => rchar(%w'] [ { } ( ) @' + alphas),
457
+ '\\' => rchar(%w'/ ] [ { } ( ) @' + alphas),
453
458
  '-' => rchar(%w'_ * ^ # @ ~'),
454
459
  '_' => rchar(%w'- * ^ # @ ~'),
455
- '(' => rchar(%w'\\ / ] [ { } ) @' + alpha),
456
- ')' => rchar(%w'\\ / ] [ { } ( @' + alpha),
460
+ '(' => rchar(%w'/ ] [ { } ) @' + alphas),
461
+ ')' => rchar(%w'/ ] [ { } ( @' + alphas),
457
462
  }
463
+ to_transform =
464
+ (0 ... chars.size).to_a.select{|i| chars[i] !~ %r"\s"}.sort_by{ rand }
465
+ to_transform = to_transform.first((to_transform.size * @transform).ceil)
466
+ to_transform.each do |i|
467
+ char = chars[i]
468
+ chars[i] = (transform[char] || lambda{char}).call
469
+ end
458
470
 
459
- (@noise * @captcha.size).ceil.times do |i|
460
- cbyte = @captcha[i]
461
- if cell =~ %r"nbsp;"
471
+ # background noise
472
+ to_noise =
473
+ (0 ... chars.size).to_a.select{|i| chars[i] =~ %r" "}.sort_by{ rand }
474
+ to_noise = to_noise.first((to_noise.size * @noise).ceil)
475
+ noisy = %w`| / ( ) \\ ! [ ] < > ^ v V`
476
+ noise = lambda{|*a| noisy[ rand(noisy.size) ]}
477
+ to_noise.each do |i|
478
+ char = chars[i]
479
+ chars[i] = noise[char]
462
480
  end
463
- =end
464
- @captcha
465
481
  end #--}}}
466
482
 
467
483
  def element! #--{{{
468
484
  rows = []
469
485
  rows << (row = [])
470
486
  chars = @captcha.split %r//
487
+ #chars = @figlet.split %r//
471
488
  size = chars.size
472
489
  last = size - 1
473
490
 
@@ -475,53 +492,45 @@ class Flatulent
475
492
  content =
476
493
  case char
477
494
  when %r/\n/o
478
- "<br>"
495
+ #"<br>"
496
+ "\n"
479
497
  when %r/\s/o
480
- "&nbsp;"
498
+ #"&nbsp;"
499
+ " "
481
500
  when %r/([^\s])/o
482
501
  CGI.escapeHTML $1
483
502
  end
484
- Array.new(rand(10)){ content = "<span>#{ content }</span>"}
503
+ #Array.new(rand(10)){ content = "<span>#{ content }</span>"}
485
504
  row << content
486
505
  rows << (row = []) unless idx == last
487
506
  end
488
507
 
508
+ content = rows.join
509
+ #<table width='50%' border=1 bgcolor='#{ style["background"] }'><tr><td>
510
+ #</td></tr></table>
511
+ @element = <<-html
512
+ <div id='#{ @id }_element' style='#{ css }'>#{ content }</div>
513
+ html
514
+ end #--}}}
489
515
 
490
- =begin
491
- noisy = %w`| / - _ ( ) \\`
492
- alpha = ('A'..'Z').to_a + ('a'..'z').to_a
493
- transform = {
494
- '|' => rchar(%w'. * \` + , ; : '),
495
- '/' => rchar(%w'\\ ] [ { } ( ) @' + alpha),
496
- '\\' => rchar(%w'/ ] [ { } ( ) @' + alpha),
497
- '-' => rchar(%w'_ * ^ # @ ~'),
498
- '_' => rchar(%w'- * ^ # @ ~'),
499
- '(' => rchar(%w'\\ / ] [ { } ) @' + alpha),
500
- ')' => rchar(%w'\\ / ] [ { } ( @' + alpha),
501
- }
502
516
 
503
- (@noise * chars.size).ceil.times do
504
- y = rand(rows.size - 1)
505
- x = rand(rows.first.size - 1)
506
- cell = rows[y][x]
507
- next if cell =~ %r"br"
508
- char =
509
- if cell =~ %r"nbsp;"
510
- noisy[ rand(noisy.size) ]
511
- else
512
- #(transform[cell] || lambda{'.'}).call
513
- nil
514
- end
515
- rows[y][x] = char if char
516
- end
517
- =end
518
517
 
519
- content = rows.join
520
- @element = "<pre id='#{ @id }_element' style='#{ css }'>#{ content }</pre>"
521
- end #--}}}
518
+ def image options = {}
519
+ require 'RMagick'
520
+
521
+ grid = captcha.split(%r"\n").map{|row| row.split %r""}
522
+
523
+ width = grid.first.size
524
+ height = grid.size
525
+
526
+ img = Magick::Image.new width, height
527
+
528
+ img
529
+ end
530
+
522
531
 
523
532
  def rchar *list #--{{{
524
- list = list.flatten
533
+ list = list.flatten.sort_by{ rand }
525
534
  n = list.size - 1
526
535
  lambda{list[ rand(n) ]}
527
536
  end #--}}}
@@ -595,10 +604,16 @@ if $0 == __FILE__
595
604
  #p e
596
605
  #p Flatulent.decrypt(e)
597
606
 
607
+ =begin
598
608
  f = Flatulent.new #('foobar')
599
609
  puts f.figlet
600
610
  puts('-' * 79)
601
611
  puts f.vapour
602
612
  puts('-' * 79)
603
613
  puts f.captcha
614
+ =end
615
+
616
+ f = Flatulent.new
617
+ puts f.captcha
618
+
604
619
  end
@@ -1,7 +1,10 @@
1
1
  class FlatulentController < ApplicationController
2
- $:.unshift '../../lib'
3
- load 'flatulent.rb'
4
- #require 'flatulent.rb'
2
+ if ENV['RAILS_ENV'] == 'production'
3
+ require 'flatulent.rb'
4
+ else
5
+ $:.unshift '../lib'
6
+ load '../lib/flatulent.rb'
7
+ end
5
8
 
6
9
  def figlet
7
10
  render :text => Flatulent.figlet(params), :content_type => 'text/plain'
@@ -62,7 +65,6 @@ class FlatulentController < ApplicationController
62
65
 
63
66
  <form action='./' method='post'>
64
67
  <%= Flatulent.ajax %>
65
-
66
68
  <hr>
67
69
  <input type='submit' name='submit' value='submit' />
68
70
  </form>