naturecommits 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,16 @@
1
+ CommandCam - A command line image grabber
2
+ Copyright (C) 2012 Ted Burke
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program (see the file "COPYING").
16
+ If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,117 @@
1
+ {\rtf1\ansi\ansicpg1252\cocoartf1138
2
+ {\fonttbl\f0\fnil\fcharset0 Verdana;\f1\fswiss\fcharset0 ArialMT;\f2\fmodern\fcharset0 Courier;
3
+ \f3\fmodern\fcharset0 Courier-Oblique;}
4
+ {\colortbl;\red255\green255\blue255;\red0\green16\blue81;}
5
+ {\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid1\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid1}}
6
+ {\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}
7
+ \margl1440\margr1440\vieww14180\viewh14480\viewkind0
8
+ \deftab720
9
+ \pard\pardeftab720
10
+
11
+ \f0\b\fs38 \cf0 \ul \ulc0 Image Snap\
12
+
13
+ \b0\fs20 \ulnone \
14
+ by Robert Harder\
15
+ rob@iHarder.net
16
+ \b\fs38 \
17
+ \
18
+ \pard\pardeftab720\sa360
19
+
20
+ \fs28 \cf0 Capture Images from the Command Line
21
+ \f1\fs32 \
22
+ \pard\pardeftab720\sa320\qc
23
+ {\field{\*\fldinst{HYPERLINK "http://iharder.net/imagesnap"}}{\fldrslt
24
+ \f0\b0 \cf0 http://iharder.net/imagesnap}}
25
+ \f0\b0 \
26
+ \pard\pardeftab720\sa320
27
+ \cf0 ImageSnap is a Public Domain command-line tool that lets you capture still images from an iSight or other video source.\
28
+ \pard\pardeftab720\sa300
29
+
30
+ \f1\b\fs38 \cf2 Installation\
31
+ \pard\pardeftab720\sa320
32
+
33
+ \f0\b0\fs32 \cf0 Copy the
34
+ \f2\fs26 imagesnap
35
+ \f0\fs32 file to someplace on your path like
36
+ \f2\fs26 /usr/local/bin
37
+ \f0\fs32 , or leave it in a "current directory," and call it with
38
+ \f2\fs26 ./imagesnap
39
+ \f0\fs32 instead.\
40
+ Enjoy!\
41
+ \pard\pardeftab720\sa300
42
+
43
+ \f1\b\fs38 \cf2 Usage\
44
+ \pard\pardeftab720\sa320
45
+
46
+ \f0\b0\fs32 \cf0 To capture an image simply run the program from the command line.\
47
+ \pard\pardeftab720
48
+
49
+ \f2\fs26 \cf0 $ imagesnap\
50
+ Capturing image from device "iSight"..................snapshot.jpg\
51
+ \pard\pardeftab720\sa320
52
+
53
+ \f0\fs32 \cf0 \
54
+ To specify a filename, make that your last argument:\
55
+ \pard\pardeftab720
56
+
57
+ \f2\fs26 \cf0 $ imagesnap icu.jpg\
58
+ Capturing image from device "iSight"..................icu.jpg\
59
+ \pard\pardeftab720\sa320
60
+
61
+ \f0\fs32 \cf0 \
62
+ If you have multiple video devices attached to your computer, use the
63
+ \f2\fs26 -l
64
+ \f0\fs32 ("el") flag to list them:\
65
+ \pard\pardeftab720
66
+
67
+ \f2\fs26 \cf0 $ imagesnap -l\
68
+ Video Devices:\
69
+ iSight\
70
+ DV\
71
+ \pard\pardeftab720\sa320
72
+
73
+ \f0\fs32 \cf0 \
74
+ To select a specific video device use the
75
+ \f2\fs26 -d
76
+ \f3\i device
77
+ \f0\i0\fs32 flag:\
78
+ \pard\pardeftab720
79
+
80
+ \f2\fs26 \cf0 $ imagesnap -d DV\
81
+ Capturing image from device "DV"..................snapshot.jpg\
82
+ \pard\pardeftab720\sa320
83
+
84
+ \f0\fs32 \cf0 \
85
+ To output a jpeg representation to standard out (stdout), use a dash for the filename:\
86
+ \pard\pardeftab720
87
+
88
+ \f2\fs26 \cf0 $ ssh johndoe@somewhere.com /usr/local/bin/imagesnap - > snapshot.jpg\
89
+ $ open snapshot.jpg\
90
+ \pard\pardeftab720\sa300
91
+
92
+ \f1\b\fs38 \cf2 \
93
+ Image Formats\
94
+ \pard\pardeftab720\sa320
95
+
96
+ \f0\b0\fs32 \cf0 The following image formats are supported and are determined by the filename extension: JPEG, TIFF, PNG, GIF, BMP.\
97
+ \pard\pardeftab720\sa300
98
+
99
+ \f1\b\fs38 \cf2 Changes\
100
+ \pard\tx220\tx720\pardeftab720\li720\fi-720\sa320
101
+ \ls1\ilvl0
102
+ \f0\b0\fs32 \cf0 {\listtext \'95 }v0.2.5 - Added option to delay the first snapshot for some time. Added a time-lapse feature (thanks, Bas Zoetekouw).\
103
+ {\listtext \'95 }v0.2.4 - Found bug that caused crash on Mac OS X 10.5 (but not 10.6).\
104
+ {\listtext \'95 }v0.2.4beta - Tracking bug that causes crash on Mac OS X 10.5 (but not 10.6).\
105
+ {\listtext \'95 }v0.2.3 - Fixed bug that caused all images to be saved as TIFF. Not sure when this bug was introduced.\
106
+ {\listtext \'95 }v0.2.2 - Added ability to output jpeg to standard out. Made executable lowercase
107
+ \f2\fs26 imagesnap
108
+ \f0\fs32 .\
109
+ {\listtext \'95 }v0.2.1 - Changed name from ImageCapture to ImageSnap to avoid confusion with Apple's Image Capture application.\
110
+ {\listtext \'95 }v0.2 - Multiple file formats (not just TIFF). Faster response.\
111
+ {\listtext \'95 }v0.1 - This is the initial release.\
112
+ \pard\pardeftab720\sa300
113
+
114
+ \f1\b\fs38 \cf2 A Note About Public Domain\
115
+ \pard\pardeftab720\sa320
116
+
117
+ \f0\b0\fs32 \cf0 I have released this software into the Public Domain. That means you can do whatever you want with it. Really. You don't have to match it up with any other open source license \'97 just use it. You can rename the files, do whatever you want. If your lawyers say you have to have a license, contact me, and I'll make a special release to you under whatever reasonable license you desire: MIT, BSD, GPL, whatever.}
Binary file
data/fonts/Impact.ttf ADDED
Binary file
@@ -0,0 +1,210 @@
1
+ $:.unshift File.expand_path('.')
2
+
3
+ require "naturecommits/version"
4
+ require "tranzlate/lolspeak"
5
+ require "choice"
6
+ require "fileutils"
7
+ require "git"
8
+ require "RMagick"
9
+ require "open3"
10
+ require "launchy"
11
+ require 'yaml'
12
+ require "aws/s3"
13
+ include Magick
14
+
15
+ module NATURECOMMITS
16
+ $home = ENV['HOME']
17
+ LOLBASEDIR = File.join $home, ".naturecommits"
18
+ naturecommits_ROOT = File.join(File.dirname(__FILE__), '..')
19
+
20
+ # Specify and load config
21
+ CONFIG_FILE = '/naturecommits.yaml'
22
+ $config = YAML::load(File.open(CONFIG_FILE))
23
+ $ACCESS = $config['amazon']['access_key']
24
+ $SECRET = $config['amazon']['secret_key']
25
+ $USER = $config['user']
26
+
27
+ def is_mac?
28
+ RUBY_PLATFORM.downcase.include?("darwin")
29
+ end
30
+
31
+ def is_linux?
32
+ RUBY_PLATFORM.downcase.include?("linux")
33
+ end
34
+
35
+ def is_windows?
36
+ if RUBY_PLATFORM =~ /(win|w)32$/
37
+ true
38
+ end
39
+ end
40
+
41
+ def most_recent(dir='.')
42
+ loldir, commit_sha, commit_msg = parse_git
43
+ Dir.glob(File.join loldir, "*").max_by {|f| File.mtime(f)}
44
+ end
45
+
46
+ def loldir(dir='.')
47
+ loldir, commit_sha, commit_msg = parse_git
48
+ return loldir
49
+ end
50
+
51
+ def parse_git(dir='.')
52
+ g = Git.open('.')
53
+ commit = g.log.first
54
+ commit_msg = commit.message.split("\n").first
55
+ commit_sha = commit.sha[0..10]
56
+ basename = File.basename(g.dir.to_s)
57
+ basename.sub!(/^\./, 'dot') #no invisible directories in output, thanks!
58
+ loldir = File.join LOLBASEDIR, basename
59
+ return loldir, commit_sha, commit_msg
60
+ end
61
+
62
+ def capture(capture_delay=0, is_test=false, test_msg=nil, test_sha=nil)
63
+ #
64
+ # Read the git repo information from the current working directory
65
+ #
66
+ if not is_test
67
+ loldir, commit_sha, commit_msg = parse_git
68
+ else
69
+ commit_msg = test_msg
70
+ commit_sha = test_sha
71
+ loldir = File.join LOLBASEDIR, "test"
72
+ end
73
+
74
+ #
75
+ # lolspeak translate the message
76
+ #
77
+ if (ENV['naturecommits_TRANZLATE'] == '1' || false)
78
+ commit_msg = commit_msg.tranzlate
79
+ end
80
+
81
+ #
82
+ # Create a directory to hold the lolimages
83
+ #
84
+ if not File.directory? loldir
85
+ FileUtils.mkdir_p loldir
86
+ end
87
+
88
+ #
89
+ # SMILE FOR THE CAMERA! 3...2...1...
90
+ # We're just assuming the captured image is 640x480 for now, we may
91
+ # need updates to the imagesnap program to manually set this (or resize)
92
+ # if this changes on future mac isights.
93
+ #
94
+ puts "*** Preserving this moment in history. ***"
95
+ snapshot_loc = File.join(loldir, "tmp_snapshot.jpg")
96
+ if is_mac?
97
+ naturecommits_RT = File.join(File.dirname(__FILE__), '..')
98
+ imagesnap_bin = File.join(naturecommits_RT, "ext", "imagesnap", "imagesnap")
99
+ system("#{imagesnap_bin} -q #{snapshot_loc} -w #{capture_delay}")
100
+ elsif is_linux?
101
+ tmpdir = File.expand_path("#{loldir}/tmpdir#{rand(1000)}/")
102
+ FileUtils.mkdir_p( tmpdir )
103
+ # There's no way to give a capture delay in mplayer, but a number of frame
104
+ # I've found that 6 is a good value for me.
105
+ frames = if capture_delay != 0 then capture_delay else 6 end
106
+
107
+ # mplayer's output is ugly and useless, let's throw it away
108
+ _, r, _ = Open3.popen3("mplayer -vo jpeg:outdir=#{tmpdir} -frames #{frames} tv://")
109
+ # looks like we still need to read the output for something to happen
110
+ r.read
111
+ FileUtils.mv(tmpdir + "/%08d.jpg" % frames, snapshot_loc)
112
+ FileUtils.rm_rf( tmpdir )
113
+ elsif is_windows?
114
+ naturecommits_RT = File.join(File.dirname(__FILE__), '..')
115
+ commandcam_exe = File.join(naturecommits_RT, "ext", "CommandCam", "CommandCam.exe")
116
+ # DirectShow takes a while to show... at least for me anyway
117
+ delaycmd = " /delay 3000"
118
+ if capture_delay > 0
119
+ # CommandCam delay is in milliseconds
120
+ delaycmd = " /delay #{capture_delay * 1000}"
121
+ end
122
+ _, r, _ = Open3.popen3("#{commandcam_exe} /filename #{snapshot_loc}#{delaycmd}")
123
+ # looks like we still need to read the output for something to happen
124
+ r.read
125
+ end
126
+
127
+
128
+ #
129
+ # Process the image with ImageMagick to add loltext
130
+ #
131
+
132
+ # read in the image, and resize it via the canvas
133
+ canvas = ImageList.new("#{snapshot_loc}")
134
+ if (canvas.columns > 640 || canvas.rows > 480)
135
+ canvas.resize_to_fill!(640,480)
136
+ end
137
+
138
+ # create a draw object for annotation
139
+ draw = Magick::Draw.new
140
+ #if is_mac?
141
+ # draw.font = "/Library/Fonts/Impact.ttf"
142
+ #else
143
+ # draw.font = "/usr/share/fonts/TTF/impact.ttf"
144
+ #end
145
+ naturecommits_RT = File.join(File.dirname(__FILE__), '..')
146
+ draw.font = File.join(naturecommits_RT, "fonts", "Impact.ttf")
147
+
148
+ draw.fill = 'white'
149
+ draw.stroke = 'black'
150
+
151
+ # convenience method for word wrapping
152
+ # based on https://github.com/cmdrkeene/memegen/blob/master/lib/meme_generator.rb
153
+ def word_wrap(text, col = 27)
154
+ wrapped = text.gsub(/(.{1,#{col + 4}})(\s+|\Z)/, "\\1\n")
155
+ wrapped.chomp!
156
+ end
157
+
158
+ draw.annotate(canvas, 0, 0, 0, 0, commit_sha) do
159
+ self.gravity = NorthEastGravity
160
+ self.pointsize = 32
161
+ self.stroke_width = 2
162
+ end
163
+
164
+ draw.annotate(canvas, 0, 0, 0, 0, word_wrap(commit_msg)) do
165
+ self.gravity = SouthWestGravity
166
+ self.pointsize = 48
167
+ self.interline_spacing = -(48 / 5) if self.respond_to?(:interline_spacing)
168
+ self.stroke_width = 2
169
+ end
170
+
171
+ #
172
+ # Squash the images and write the files
173
+ #
174
+ #canvas.flatten_images.write("#{loldir}/#{commit_sha}.jpg")
175
+ canvas.write(File.join loldir, "#{$USER}_#{commit_sha}.jpg")
176
+ FileUtils.rm(snapshot_loc)
177
+
178
+ #
179
+ # Add to Amazon S3
180
+ #
181
+ local_file = "#{loldir}/#{$USER}_#{commit_sha}.jpg"
182
+
183
+ # bucket & mime-type
184
+ bucket = 'naturecommits'
185
+ mime_type = 'image/jpeg'
186
+
187
+ AWS::S3::Base.establish_connection!(
188
+ :access_key_id => $ACCESS,
189
+ :secret_access_key => $SECRET
190
+ )
191
+
192
+ base_name = File.basename(local_file)
193
+
194
+ puts "*** Uploading #{local_file} as '#{base_name}' to '#{bucket}' ***"
195
+
196
+ AWS::S3::S3Object.store(
197
+ base_name,
198
+ File.open(local_file),
199
+ bucket,
200
+ :content_type => mime_type
201
+ )
202
+
203
+ puts "*** Uploaded! ***"
204
+
205
+ #if in test mode, open image for inspection
206
+ if is_test
207
+ Launchy.open(File.join loldir, "#{$USER}_#{commit_sha}.jpg")
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,3 @@
1
+ module NATURECOMMITS
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,101 @@
1
+ # Adapted and expanded from moar-lolspeak (https://github.com/rwtnorton/moar-lolspeak), which was
2
+ # largely taken from an old Perl script and is sadly is not available via rubygems
3
+
4
+ module Lolspeak
5
+ LOL_DICTIONARY = {
6
+ /what/ => %w{wut whut},
7
+ /you\b/ => %w{yu yous yoo u yooz},
8
+ /cture/ => %w{kshur},
9
+ /ss\b/ => %w{s zz z},
10
+ /the\b/ => %w{teh},
11
+ /more/ => %w{moar},
12
+ /my/ => %w{mah mai},
13
+ /are/ => %w{is ar},
14
+ /eese/ => %w{eez},
15
+ /ph/ => %w{f},
16
+ /as\b/ => %w{az},
17
+ /seriously/ => %w{srsly},
18
+ /sion/ => %w{shun},
19
+ /just/ => %w{jus},
20
+ /ose\b/ => %w{oze},
21
+ /eady/ => %w{eddy},
22
+ /ome?\b/ => %w{um},
23
+ /of\b/ => %w{of ov of},
24
+ /uestion/ => %w{wesjun},
25
+ /want/ => %w{wants},
26
+ /ead\b/ => %w{edd},
27
+ /ck/ => %w{kk kkk},
28
+ /sion/ => %w{shun},
29
+ /cat|kitten|kitty/ => %w{kitteh kittehz cat fuzzeh fuzzyrumpus foozles fuzzbut fluffernutter beast mew},
30
+ /eak/ => %w{ekk},
31
+ /age/ => %w{uj},
32
+ /like/ => %w{likez liek licks},
33
+ /love/ => %w{lovez lub lubs luv lurve lurves},
34
+ /\bis\b/ => ['ar teh','ar'],
35
+ /nd\b/ => %w{n n'},
36
+ /who/ => %w{hoo},
37
+ /'/ => [''],
38
+ /ese\b/ => %w{eez},
39
+ /outh/ => %w{owf},
40
+ /scio/ => %w{shu},
41
+ /esque/ => %w{esk},
42
+ /ture/ => %w{chur},
43
+ /\btoo?\b/ => %w{to t 2 to t},
44
+ /tious/ => %w{shus},
45
+ /sure\b/ => %w{shur},
46
+ /tty\b/ => %w{tteh},
47
+ /were/ => %w{was},
48
+ /ok\b|okay/ => %w{kthxbye!},
49
+ /\ba\b/ => %w{uh},
50
+ /ym/ => %w{im},
51
+ /fish/ => %w{ghoti},
52
+ /thy\b/ => %w{fee},
53
+ /\wly\w/ => %w{li},
54
+ /que\w/ => %w{kwe},
55
+ /\both/ => %w{udd},
56
+ /though\b/ => %w{tho},
57
+ /(t|r|en)ough/ => %w{\1uff},
58
+ /ought/ => %w{awt},
59
+ /ease/ => %w{eez},
60
+ /ing\b/ => %w{in ins ng ing in'},
61
+ /have/ => ['haz', 'hav', 'haz a'],
62
+ /has/ => %w{haz gots},
63
+ /your/ => %w{yur ur yore yoar},
64
+ /ove\b/ => %w{oov ove uuv uv oove},
65
+ /for/ => %w{for 4 fr fur for foar},
66
+ /thank/ => %w{fank tank thx thnx},
67
+ /good/ => %w{gud goed guud gude gewd goot gut},
68
+ /really/ => %w{rly rily rilly rilleh},
69
+ /world/ => %w{wurrld whirld wurld wrld},
70
+ /i'?m\b/ => ['im', 'i yam', 'i iz'],
71
+ /(?!e)ight/ => %w{ite},
72
+ /(?!ues)tion/ => %w{shun},
73
+ /you'?re/ => %w{yore yr},
74
+ /can\si\s(?:ple(?:a|e)(?:s|z)e?)?\s?have\sa/ => ['i can haz'],
75
+ /(?:hello|\bhi\b|\bhey\b|howdy|\byo\b),?/ => ['oh hai,'],
76
+ /(?:god\b|allah|buddah?|diety|lord)/ => ['ceiling cat'],
77
+ /er\b|are|ere/ => %w{r},
78
+ /y\b|ey\b/ => %w{eh},
79
+ /ea/ => %w{ee},
80
+ }
81
+
82
+ def self.tranzlate(str)
83
+ lolstr = str.dup
84
+ LOL_DICTIONARY.each do |english, lolspeak|
85
+ lolstr.gsub!(english, lolspeak.sample)
86
+ end
87
+
88
+ lolstr << '! kthxbye!' if rand(10) == 2
89
+ lolstr.gsub!(/(\?|!|,|\.)+/, '!')
90
+
91
+ lolstr.upcase
92
+ end
93
+ end
94
+
95
+ class String
96
+ unless method_defined?(:tranzlate)
97
+ def tranzlate
98
+ Lolspeak.tranzlate(self)
99
+ end
100
+ end
101
+ end