meminator 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ *.rbc
2
+ *.swp
3
+ /TAGS
4
+ /doc
5
+ /pkg
6
+ /tmp
7
+ .DS_Store
@@ -0,0 +1,125 @@
1
+ === 1.10 / 2010-04-12
2
+
3
+ * Minor Enhancements
4
+ * Added link to bookmarklet for retrieving meme values. Commit by Pat
5
+ Nakajima
6
+ * Added a --text flag to skip pasting the URL. Pull Request #32 by Michael
7
+ Deering.
8
+ * Added Arnold. Commit by Brandon Keene.
9
+ * Added Ask Cathy. Commit by Pat Nakajima.
10
+ * Added Beiber. Commit by Brandon Keene.
11
+ * Added Charlie Sheen. Commit by Pat Nakajima.
12
+ * Added Chill Out Lemur. Commit by Brandon Keene.
13
+ * Added Kanye. Commit by Pat Nakajima.
14
+ * Added Kim Jong Il. Commit by Brandon Keene.
15
+ * Added Milhouse. Commit by Pat Nakajima.
16
+ * Added More Bear. Pull Request #29 by Matt Griffin.
17
+ * Added Red Shirt Guy. Commit by Brandon Keene.
18
+ * Added Sassy Spillman. Commit by Brandon Keene.
19
+ * Added Yoda. Pull Request #30 by Dean Strelau.
20
+
21
+ * Bug Fix
22
+ * Fixed Serious Fish. Pull Request #31 by Will Farrington.
23
+ * meme is now executable. Commit by Pat Nakajima.
24
+
25
+ === 1.9 / 2010-03-28
26
+
27
+ * Minor Enhancements
28
+ * meme_generator will use pasteboard if it is installed. This allows memes
29
+ to easily be used in any OS X app which handles image data.
30
+ * Added Challenge Accepted. Pull Request #27 by Mark Turner.
31
+
32
+ * Bug Fix
33
+ * Only add the default line when it is present. Pull Request #26 by Matt
34
+ Margolis.
35
+
36
+ === 1.8 / 2011-03-22
37
+
38
+ * Minor Enhancements
39
+ * Added Bear Grylls. Pull Request #25 by Lee Jarvis.
40
+ * Added Batman/Joker. Pull Request #22 by Arthur Chiu.
41
+ * Added Neo/Agent Smith. Pull Request #22 by Arthur Chiu.
42
+ * Added The Rock Driving. Pull Request #22 by Arthur Chiu.
43
+ * Added Snob. Pull Request #22 by Arthur Chiu.
44
+
45
+ === 1.7.1 / 2011-03-18
46
+
47
+ * Bug Fix
48
+ * Meme::advice_dog now accepts an optional first line.
49
+
50
+ === 1.7 / 2011-03-18
51
+
52
+ * Minor enhancement
53
+ * Inception now supports more than two lines. Pull Request #20 by Arthur
54
+ Chiu.
55
+
56
+ === 1.6 / 2011-03-17
57
+
58
+ * Minor enhancements
59
+ * <tt>meme --list</tt> is now sorted.
60
+ * +meme+ now accepts multiple lines. Not every generator accepts multiple
61
+ lines so use with care. Pull Request #18 by Arthur Chiu.
62
+ * Added Anteater. Pull Request #14 by Aaron Patterson.
63
+ * Added Cool Story House. Pull Request #16 by Dean Strelau.
64
+ * Added Creeper. Pull Request #15 by Aaron Patterson.
65
+ * Added Futurama Fry. Pull Request #16 by Dean Strelau.
66
+ * Added High Expectations Asian Father. Pull Request #18 by Arthur Chiu.
67
+ * Added Inception. Pull Request #18 by Arthur Chiu.
68
+ * Added Keanu. Pull Request #16 by Dean Strelau.
69
+ * Added Minecraft. Pull Request #15 by Aaron Patterson.
70
+ * Added ORLY Owl. Pull Request #18 by Arthur Chiu.
71
+ * Added Spiderman. Pull Request #18 by Arthur Chiu.
72
+ * Added Uncle Sam Points. Pull Request #13 by Aaron Patteron.
73
+ * Added Unicorn Boy. Pull Request #19 by Aaron Patterson.
74
+ * Added Victory Baby. Pull Request #16 by Dean Strelau.
75
+ * GENERATORS hash additions are now aligned. Pull Request #16 by Dean
76
+ Strelau.
77
+
78
+ === 1.5 / 2011-03-16
79
+
80
+ * Minor enhancement
81
+ * Added Swedish Chef, bork bork bork. Pull Request #12 by Aaron Patterson.
82
+
83
+ === 1.4 / 2011-03-15
84
+
85
+ * Minor enhancement
86
+ * Added Butthurt Dweller. Pull Request #11 by Pete Higgins.
87
+
88
+ === 1.3 / 2011-03-10
89
+
90
+ * Minor enhancements
91
+ * Added Scumbag Steve. Pull Request #9 by Aaron Patterson
92
+ * <tt>meme > foo.jpg</tt> will download the generated image. Pull Request
93
+ #9 by Aaron Patterson
94
+ * Added Most Interesting Man in the World and Courage Wolf. Pull Request
95
+ #10 by postmodern.
96
+
97
+ === 1.2.2 / 2011-02-22
98
+
99
+ * Bug Fix
100
+ * Don't print ERROR when we're exiting normally.
101
+
102
+ === 1.2.1 / 2011-02-22
103
+
104
+ * Bug Fix
105
+ * A proper error is now printed (instead of crashing) when `meme` is run
106
+ without both lines. Bug #7 by Trevor Hartman.
107
+
108
+ === 1.2 / 2011-02-11
109
+
110
+ * Minor enhancements
111
+ * Added Hipster mermaid. Pull Request #6 by Josep M. Bach.
112
+ * Support xclip on linux. Pull Request #5 by Matthew M. Boedicker.
113
+
114
+ === 1.1 / 2011-02-09
115
+
116
+ * Minor enhancements
117
+ * Added 13 new templates. Pull Request #4 by Josep M. Bach.
118
+ * Meme::run now returns the link. Pull Request #2 by Josep M. Bach.
119
+ * Better template lookup. Patch by James Tucker.
120
+
121
+ === 1.0 / 2011-02-08
122
+
123
+ * Major enhancements
124
+ * Birthday!
125
+
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2011 Eric Hodel
4
+ Copyright (c) 2012 Rich Healey
5
+
6
+ Original work remains the property of the original author, Eric Hodel
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ 'Software'), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/meme
6
+ lib/meme.rb
@@ -0,0 +1,56 @@
1
+ NOTE:
2
+
3
+ To ease the addition of new memes, use this handy bookmarklet:
4
+
5
+ http://bookmarklets.heroku.com/bookmarklets/1814
6
+
7
+ = meme_generator
8
+
9
+ * http://github.com/drbrain/meme
10
+ * http://docs.seattlerb.org/meme_generator
11
+
12
+ == DESCRIPTION:
13
+
14
+ Generate meme images using http://memegenerator.net! Save yourself some time!
15
+
16
+ == FEATURES/PROBLEMS:
17
+
18
+ * Features many popular meme pictures
19
+ * No tests
20
+
21
+ == SYNOPSIS:
22
+
23
+ Generate a Y U NO meme:
24
+
25
+ $ meme Y_U_NO 'write tests?'
26
+
27
+ Generate a Y U NO meme url only, no clipboard or pulling of the image data:
28
+
29
+ $ meme --text Y_U_NO 'write tests?'
30
+
31
+ See a list of available generators
32
+
33
+ $ meme --list
34
+
35
+ You can also drive it like an API.
36
+
37
+ == REQUIREMENTS:
38
+
39
+ * nokogiri
40
+ * internet connection
41
+
42
+ == INSTALL:
43
+
44
+ gem install meme_generator
45
+
46
+ == DEVELOPERS:
47
+
48
+ After checking out the source, run:
49
+
50
+ $ rake newb
51
+
52
+ This task will install any missing dependencies, run the tests/specs,
53
+ and generate the RDoc.
54
+
55
+ == LICENSE:
56
+
@@ -0,0 +1,264 @@
1
+ require 'net/http'
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+
6
+ ##
7
+ # Generate memes using http://memegenerator.net
8
+
9
+ class Meme
10
+
11
+ ##
12
+ # Sometimes your meme will have an error, fix it!
13
+
14
+ class Error < RuntimeError; end
15
+
16
+ ##
17
+ # Every meme generator needs a version
18
+
19
+ VERSION = '1.10'
20
+
21
+ ##
22
+ # For statistics!
23
+
24
+ USER_AGENT = "meme/#{VERSION} Ruby/#{RUBY_VERSION}"
25
+
26
+ ##
27
+ # We have some generators up-in-here
28
+
29
+ GENERATORS = Hash.new do |_, k|
30
+ raise Error, "unknown generator #{k}"
31
+ end
32
+
33
+ ##
34
+ # For creating advice-dog type meme images.
35
+ #
36
+ # These can accept up to two lines of text
37
+
38
+ def self.advice_dog name, id, template_name, first_line = nil
39
+ template = [id, 'AdviceDogSpinoff', template_name, first_line]
40
+ template.compact
41
+
42
+ GENERATORS[name] = template
43
+ end
44
+
45
+ ##
46
+ # For creating vertical type meme images
47
+ #
48
+ # These can accept multiple lines of text
49
+
50
+ def self.vertical name, id, template_name
51
+ GENERATORS[name] = [id, 'Vertical', template_name]
52
+ end
53
+
54
+ # keep generators in alphabetical order
55
+ advice_dog 'ANTEATER', 41191, 'anteater'
56
+ advice_dog 'A_DODSON', 106375, 'Antoine-Dodson'
57
+ advice_dog 'A_DOG', 940, 'Advice-Dog'
58
+ advice_dog 'A_FATHER', 1436, 'High-Expectations-Asian-Father'
59
+ advice_dog 'ARNOLD', 1236, 'Angry-Arnold'
60
+ advice_dog 'BEAR-GRYLLS', 89714, 'Bear-Grylls'
61
+ advice_dog 'BUTTHURT_DWELLER', 1438, 'Butthurt-Dweller'
62
+ advice_dog 'B_FROG', 1211, 'Foul-Bachelorette-Frog'
63
+ advice_dog 'B_FROG2', 1045, 'Foul-Bachelor-Frog'
64
+ advice_dog 'BEIBER', 11809, 'Justin-Beiber'
65
+ advice_dog 'CATHY', 622381, 'AckCathy'
66
+ advice_dog 'CHALLENGE_ACCEPTED', 275025, 'Challenge-Accepted'
67
+ advice_dog 'COOL_STORY_HOUSE', 16948, 'cool-story-bro-house'
68
+ advice_dog 'CREEPER', 173501, 'Minecraft-Creeper'
69
+ advice_dog 'C_WOLF', 931, 'Courage-Wolf'
70
+ advice_dog 'C_LEMUR', 1227, 'Chill-Out-Lemur'
71
+ advice_dog 'F_FRY', 84688, 'Futurama-Fry'
72
+ advice_dog 'G_GRANDPA', 185650, 'Grumpy-Grandpa'
73
+ advice_dog 'H_MERMAID', 405224, 'Hipster-Mermaid'
74
+ advice_dog 'I_DONT_ALWAYS', 38926, 'The-Most-Interesting-Man-in-the-World'
75
+ advice_dog 'I_WOLF', 926, 'Insanity-Wolf'
76
+ advice_dog 'JESUS', 1281, 'jesus-says'
77
+ advice_dog 'J_DUCREUX', 1356, 'Joseph-Ducreux'
78
+ advice_dog 'KANYE', 622033, 'kanyee'
79
+ advice_dog 'KEANU', 47718, 'Keanu-reeves'
80
+ advice_dog 'KJI', 5840, 'Kim-Jong-IL'
81
+ advice_dog 'MILHOUSE', 228797, 'Millhouse'
82
+ advice_dog 'MINECRAFT', 122309, 'Minecraft'
83
+ advice_dog 'MORE_BEAR', 33675, 'More-Bear'
84
+ advice_dog 'O-RLY-OWL', 117041, 'O-RLY-OWL', 'ORLY???'
85
+ advice_dog 'OBAMA', 1332, 'Obama-'
86
+ advice_dog 'PHILOSORAPTOR', 984, 'Philosoraptor'
87
+ advice_dog 'P_OAK', 24321, 'Professor-Oak'
88
+ advice_dog 'P_OBAMA', 45557, 'Pissed-off-Obama'
89
+ advice_dog 'R_BLACK', 547955, 'Rebecca-Black-Meme'
90
+ advice_dog 'REDSHIRT', 239371, 'red-shirt-guy'
91
+ advice_dog 'SCUMBAG', 364688, 'Scumbag-Steve'
92
+ advice_dog 'SERIOUS_FISH', 7054219, 'Serious-fish-spongebob'
93
+ advice_dog 'SHEEN', 488762, 'Charlie-Sheen'
94
+ advice_dog 'SNOB', 2994, 'Snob'
95
+ advice_dog 'SPARTA', 1013, 'sparta'
96
+ advice_dog 'SPIDERMAN', 1037, 'Question-Spiderman'
97
+ advice_dog 'SPILLMAN', 622133, 'Sassy-Spillman'
98
+ advice_dog 'SWEDISH_CHEF', 186651, 'Swedish-Chef'
99
+ advice_dog 'S_AWKWARD_PENGUIN', 983, 'Socially-Awkward-Penguin'
100
+ advice_dog 'TOWNCRIER', 434537, 'Towncrier'
101
+ advice_dog 'TROLLFACE', 1030, 'Troll-Face'
102
+ advice_dog 'UNICORN_BOY', 57022, 'unicorn-boy'
103
+ advice_dog 'US_POINT', 131083, 'Uncle-Sam-Point', 'I WANT YOU'
104
+ advice_dog 'V_BABY', 11140, 'Victory-Baby'
105
+ advice_dog 'XZIBIT', 3114, 'XZIBIT'
106
+ advice_dog 'Y_U_NO', 165241, 'Y-U-NO', 'Y U NO'
107
+ advice_dog 'YODA', 963, 'Advice-Yoda-Gives'
108
+
109
+ vertical 'BATMAN', 148359, 'batman-panal-ryan'
110
+ vertical 'INCEPTION', 107949, 'Inception'
111
+ vertical 'NEO', 173419, 'Neo'
112
+ vertical 'THE_ROCK', 417195, 'The-Rock-driving'
113
+
114
+ # keep generators in alphabetical order
115
+
116
+ ##
117
+ # Looks up generator name
118
+
119
+ def GENERATORS.match(name)
120
+ # TODO meme Y U NO DEMETAPHONE?
121
+ return self[name] if has_key? name
122
+ matcher = Regexp.new(name, Regexp::IGNORECASE)
123
+ _, generator = find { |k,v| matcher =~ k || v.grep(matcher).any? }
124
+ generator || self[name] # raises the error if generator is nil
125
+ end
126
+
127
+ ##
128
+ # Interface for the executable
129
+
130
+ def self.run argv = ARGV
131
+ generator = ARGV.shift
132
+
133
+ if generator == '--list' then
134
+ width = GENERATORS.keys.map { |command| command.length }.max
135
+
136
+ GENERATORS.sort.each do |command, (id, name, _)|
137
+ puts "%-*s %s" % [width, command, name]
138
+ end
139
+
140
+ exit
141
+ end
142
+
143
+ text_only = if generator == '--text'
144
+ generator = ARGV.shift
145
+ true
146
+ else
147
+ false
148
+ end
149
+
150
+ # puts "text_only:#{text_only} generator:#{generator}"
151
+
152
+ abort "#{$0} [GENERATOR|--list] LINE [ADDITONAL_LINES]" if ARGV.empty?
153
+
154
+ meme = new generator
155
+ link = meme.generate(*ARGV)
156
+
157
+ meme.paste(link) unless text_only
158
+
159
+ if $stdout.tty? || text_only
160
+ puts link
161
+ else
162
+ puts meme.fetch link
163
+ end
164
+ link
165
+ rescue Interrupt
166
+ exit
167
+ rescue SystemExit
168
+ raise
169
+ rescue Exception => e
170
+ puts e.backtrace.join "\n\t" if $DEBUG
171
+ abort "ERROR: #{e.message} (#{e.class})"
172
+ end
173
+
174
+ ##
175
+ # Generates links for +generator+
176
+
177
+ def initialize generator
178
+ @template_id, @template_type, @generator_name, @default_line = GENERATORS.match generator
179
+ end
180
+
181
+ ##
182
+ # Generates a meme with +line1+ and +line2+. For some generators you only
183
+ # have to supply one line because the first line is defaulted for you.
184
+ # Isn't that great?
185
+
186
+ def generate *args
187
+ url = URI.parse 'http://memegenerator.net/Instance/CreateOrEdit'
188
+ res = nil
189
+ location = nil
190
+
191
+ # Prepend the default line if this meme has one and we only had 1 text input
192
+ args.unshift @default_line if @default_line and args.size <= 1
193
+
194
+ raise Error, "two lines are required for #{@generator_name}" unless
195
+ args.size > 1
196
+
197
+ post_data = { 'templateType' => @template_type,
198
+ 'templateID' => @template_id,
199
+ 'generatorName' => @generator_name }
200
+
201
+ # go through each argument and add it back into the post data as textN
202
+ (0..args.size).map {|num| post_data.merge! "text#{num}" => args[num] }
203
+
204
+ Net::HTTP.start url.host do |http|
205
+ post = Net::HTTP::Post.new url.path
206
+ post['User-Agent'] = USER_AGENT
207
+ post.set_form_data post_data
208
+
209
+ res = http.request post
210
+
211
+ location = res['Location']
212
+ redirect = url + location
213
+
214
+ get = Net::HTTP::Get.new redirect.request_uri
215
+ get['User-Agent'] = USER_AGENT
216
+
217
+ res = http.request get
218
+ end
219
+
220
+ if Net::HTTPSuccess === res then
221
+ doc = Nokogiri.HTML res.body
222
+ doc.css("a[href=\"#{location}\"] img").first['src']
223
+ else
224
+ raise Error, "memegenerator.net appears to be down, got #{res.code}"
225
+ end
226
+ end
227
+
228
+ def fetch link
229
+ url = URI.parse link
230
+ res = nil
231
+
232
+ Net::HTTP.start url.host do |http|
233
+ get = Net::HTTP::Get.new url.request_uri
234
+ get['User-Agent'] = USER_AGENT
235
+
236
+ res = http.request get
237
+ end
238
+ res.body
239
+ end
240
+
241
+ ##
242
+ # Tries to find clipboard copy executable and if found puts +link+ in your
243
+ # clipboard.
244
+
245
+ def paste link
246
+ require 'pasteboard'
247
+
248
+ clipboard = Pasteboard.new
249
+
250
+ jpeg = fetch link
251
+
252
+ clipboard.put_jpeg_url jpeg, link
253
+ rescue LoadError
254
+ clipboard = %w{
255
+ /usr/bin/pbcopy
256
+ /usr/bin/xclip
257
+ }.find { |path| File.exist? path }
258
+
259
+ if clipboard
260
+ IO.popen clipboard, 'w' do |io| io.write link end
261
+ end
262
+ end
263
+
264
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "meminator"
3
+ s.version = "0.0.0"
4
+ s.authors = ["Eric Hodel", "Rich Healey"]
5
+ s.email = ["richo@psych0tik.net"]
6
+ s.homepage = "http://github.com/richoH/meminator"
7
+ s.summary = "API to retrieve urls for memes"
8
+ s.description = s.summary
9
+
10
+ s.add_dependency "nokogiri"
11
+
12
+ s.files = `git ls-files`.split("\n")
13
+ # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ s.require_paths = ["lib"]
15
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meminator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Hodel
9
+ - Rich Healey
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-05-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ description: API to retrieve urls for memes
32
+ email:
33
+ - richo@psych0tik.net
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - History.txt
40
+ - LICENSE
41
+ - Manifest.txt
42
+ - README.md
43
+ - lib/meme.rb
44
+ - meminator.gemspec
45
+ homepage: http://github.com/richoH/meminator
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.23
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: API to retrieve urls for memes
69
+ test_files: []
70
+ has_rdoc: