lolcommits 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lolcommits.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # git + webcam = lol
2
+
3
+ Takes a snapshot with your Mac's built-in iSight webcam every time you git commit code, and archives a lolcat style image with it.
4
+
5
+ By default, the lolimages are stored by a Github style short SHA in a `~/.lolcommits` directory created for you.
6
+
7
+ ## Installation (for new gem-y version)
8
+ We've gotten rid of most of the dependency chain, yay!
9
+
10
+ You'll need imagesnap and imagemagick installed. Homebrew makes this easy. Simply do:
11
+
12
+ brew install imagemagick
13
+ brew install imagesnap
14
+
15
+ This will take care of the non-Ruby dependencies. Then do:
16
+
17
+ gem install lolcommits
18
+
19
+ You're all set! To enable lolcommits for a git repo, go to the base directory of the repository, and run:
20
+
21
+ lolcommits --enable
22
+
23
+ Likewise, you can disable it via `lolcommits --disable`.
24
+
25
+ ## Sample images
26
+ Please add your own lolcommit to these samples! Just fork this repo, add it to this section of the README, and send me a pull request.
27
+ <img width='320' height='240' src="https://github.com/mroth/lolcommits/raw/gh-pages/sample2.jpg" />
28
+ &nbsp;
29
+ <img width='320' height='240' src="https://github.com/mroth/lolcommits/raw/gh-pages/sample5.jpg" />
30
+ <br/>
31
+ <img width='320' height='240' src="https://github.com/mroth/lolcommits/raw/gh-pages/sample4.jpg" />
32
+ &nbsp;
33
+
34
+ ## Upgrading from an old (non-gem) version?
35
+ If you used the autoinstaller, here's how to get rid of the old stuff (I think)
36
+
37
+ For all active lolrepos, go into them and do:
38
+
39
+ git hooks --uninstall
40
+
41
+ You might want to get rid of the copied binary for imagesnap and switch over to the homebrew-managed version, if so `rm /usr/local/bin/imagesnap`.
42
+
43
+ If you want to get rid of git-hooks entirly (it won't hurt anything, but we dont use it anymore), you can also do:
44
+
45
+ rm /usr/local/bin/git-hooks
46
+ rm -rf ~/.git_hooks
47
+ rm -rf ~/.githooks_src
48
+
49
+ <!--
50
+ # LEGACY README STUFF LIVES BELOW THIS LINE
51
+
52
+ ## Prerequisites
53
+
54
+ - ImageMagick (`brew install imagemagick` assuming you are on a mac using [Homebrew](http://mxcl.github.com/homebrew/))
55
+ - RMagick and ruby-git gems (`bundle install` when in this directory)
56
+ - [ImageSnap](http://www.iharder.net/current/macosx/imagesnap/) (included)
57
+
58
+ ## Installation
59
+
60
+ ### The boring way
61
+ Copy `bin/imagesnap` to somewhere in your `$PATH`. Make `lolcommit.rb` a post-commit hook in the repo you want it to run for.
62
+
63
+ ### The awesome way (works for multiple repos)
64
+ Run `rake install`. This will do the following:
65
+
66
+ - Copy `imagesnap` to `/usr/local/bin`
67
+ - Clone and install [the git-hooks project](https://github.com/icefox/git-hooks) (adding it to `/usr/local/bin`)
68
+ - Creates your global user `~/.git_hooks` and gives you a few directories to start (pre-commit, commit-msg, and post-commit).
69
+ - Copies the main script here (`lolcommit.rb`) to your new `~/.git_hooks/post-commit` directory.
70
+ - Uses `bundler` to install any uninstalled Gem dependencies (assuming bundler is installed, manually `gem install bundler` if not, we don't auto-install it to be polite.)
71
+ - Uses `homebrew` to install ImageMagick (assuming Homebrew is installed, we don't auto-install it here to be polite.)
72
+
73
+ Once this is done, simply run `git hooks --install` while in any repository you want to use this in.
74
+
75
+ This installs [git-hooks](https://github.com/icefox/git-hooks) which gives you a global user hooks directory so you can set up other stuff easily as well. See their README for more details.
76
+
77
+ If you don't want to use `/usr/local/bin` you can provide a different
78
+ dir running `LOCAL_BINDIR=/your/path/of/choice rake install`
79
+
80
+ -->
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Migrate an existing local .lolcommits directory to Dropbox"
4
+ task :dropboxify do
5
+ dropbox_loldir = "#{$home}/Dropbox/lolcommits"
6
+ loldir = "#{$home}/.lolcommits"
7
+ backup_loldir = "#{$home}/.lolcommits.old"
8
+
9
+ #check whether we've done this already
10
+ if File.symlink? loldir
11
+ abort "already dropboxified!"
12
+ end
13
+
14
+ #create dropbox folder
15
+ if not File.directory? dropbox_loldir
16
+ FileUtils.mkdir_p dropbox_loldir
17
+ end
18
+
19
+ #backup existing loldir
20
+ if File.directory? loldir
21
+ FileUtils.mv( loldir, backup_loldir )
22
+ end
23
+
24
+ #symlink dropbox to local
25
+ FileUtils.ln_s( dropbox_loldir, loldir )
26
+
27
+ #copy over existing files
28
+ FileUtils.cp_r( "#{backup_loldir}/.", loldir)
29
+ end
data/bin/lolcommits ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'lolcommits'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'lolcommits'
8
+ end
9
+
10
+ include Lolcommits
11
+
12
+ #
13
+ # CHECK FOR FURTHER DEPENDENCIES
14
+ #
15
+
16
+ # which replacement http://stackoverflow.com/q/2108727
17
+ def command?(name)
18
+ `which #{name}`
19
+ $?.success?
20
+ end
21
+
22
+ if not command?('imagesnap')
23
+ puts "Couldn't find imagesnap in your PATH!"
24
+ puts "Easiest way to get it is to install homebrew and do `brew install imagesnap`"
25
+ exit 1
26
+ end
27
+
28
+ #
29
+ # NO ARGUMENTS SPECIFIED, HELP THE USER OUT
30
+ #
31
+ def do_noargs
32
+ #TODO: make this a contextual helper to know status of whether lolcommits is enabled
33
+ puts "Do what exactly?"
34
+ puts "Try: lolcommits --enable (when in a git repository)"
35
+ end
36
+
37
+ HOOK_PATH = ".git/hooks/post-commit"
38
+
39
+ #
40
+ # IF --ENABLE, DO ENABLE
41
+ #
42
+ def do_enable
43
+ if not File.directory? ".git/hooks"
44
+ puts "You don't appear to be in the base directory of a git project."
45
+ exit 1
46
+ end
47
+ if File.exists? HOOK_PATH
48
+ puts "A post-commit hook already exists for this project."
49
+ #TODO: disambiguate between OUR post-commit hook and something else
50
+ exit 1
51
+ end
52
+ #TODO: prompt "Do you want to install lolcommits for this git project? [Yn]"
53
+ #TODO: figure out where gem puts this, copy from there
54
+ #FileUtils.touch HOOK_PATH
55
+ doc = "#!/bin/sh\nlolcommits --capture\n"
56
+ File.open(HOOK_PATH, 'w') {|f| f.write(doc) }
57
+ FileUtils.chmod 0755, HOOK_PATH
58
+ puts "installed lolcommmit hook as:"
59
+ puts " -> #{File.expand_path(HOOK_PATH)}"
60
+ puts "(to remove later, you can use: lolcommits --disable)"
61
+ # actually we probably shouldnt symlink, but rather install a small stub that calls the one from path
62
+ # that way, as gem version changes, script updates even if new file thus breaking symlink
63
+ #File.symlink "/Users/mroth/.git_hooks/post-commit/lolcommit", ".git/hooks/post-commit"
64
+ end
65
+
66
+ #
67
+ # IF --DISABLE, DO DISABLE
68
+ #
69
+ def do_disable
70
+ if File.exists? HOOK_PATH
71
+ #TODO: check if hook file has been modified before removing
72
+ FileUtils.rm HOOK_PATH
73
+ puts "removed #{HOOK_PATH}"
74
+ else
75
+ puts "lolcommits is not enabled for this directory, so there is nothing to uninstall."
76
+ end
77
+ end
78
+
79
+ #
80
+ # IF --CAPTURE, DO CAPTURE
81
+ #
82
+ def do_capture
83
+ if Choice.choices[:test]
84
+ puts "*** capturing in test mode"
85
+ Lolcommits.capture(true, Choice.choices[:msg], Choice.choices[:sha])
86
+ else
87
+ Lolcommits.capture
88
+ end
89
+ end
90
+
91
+ #
92
+ # Command line parsing fun
93
+ #
94
+ Choice.options do
95
+
96
+ option :enable do
97
+ long "--enable"
98
+ action { do_enable }
99
+ desc "install lolcommits for this repo"
100
+ end
101
+
102
+ option :disable do
103
+ long "--disable"
104
+ action { do_disable }
105
+ desc "uninstall lolcommits for this repo"
106
+ end
107
+
108
+ option :capture do
109
+ long "--capture"
110
+ desc "capture lolcommit based on last git commit"
111
+ end
112
+
113
+ option :test do
114
+ long "--test"
115
+ desc "Run in test mode"
116
+ end
117
+
118
+ option :sha do
119
+ desc "Pass SHA manually (for test only)"
120
+ short '-s'
121
+ default "test-#{rand(10 ** 10)}"
122
+ end
123
+
124
+ option :msg do
125
+ desc "Pass commit msg manually (for test only)"
126
+ short '-m'
127
+ default "this is a test message i didnt really commit something"
128
+ end
129
+ end
130
+
131
+ #
132
+ # Handle actions manually since choice seems weird
133
+ #
134
+ if not (Choice.choices[:enable] || Choice.choices[:disable])
135
+ if Choice.choices[:capture]
136
+ do_capture()
137
+ else
138
+ do_noargs()
139
+ end
140
+ end
141
+
142
+ #if here, choice didnt do anything (NOT TRUE)
143
+ #noargs
data/lib/lolcommits.rb ADDED
@@ -0,0 +1,101 @@
1
+ require "lolcommits/version"
2
+ require "choice"
3
+ require "fileutils"
4
+ require "git"
5
+ require "RMagick"
6
+ include Magick
7
+
8
+ module Lolcommits
9
+ # Your code goes here...
10
+ $home = ENV['HOME']
11
+ LOLBASEDIR = "#{$home}/.lolcommits"
12
+
13
+ def capture(is_test=false, test_msg=nil, test_sha=nil)
14
+ #
15
+ # Read the git repo information from the current working directory
16
+ #
17
+ if not is_test
18
+ g = Git.open('.')
19
+ commit = g.log.first
20
+ commit_msg = commit.message
21
+ commit_sha = commit.sha[0..10]
22
+ basename = File.basename(g.dir.to_s)
23
+ basename.sub!(/^\./, 'dot') #no invisible directories in output, thanks!
24
+ loldir = "#{LOLBASEDIR}/#{basename}"
25
+ else
26
+ commit_msg = test_msg #Choice.choices[:msg]
27
+ commit_sha = test_sha #Choice.choices[:sha]
28
+ loldir = "#{LOLBASEDIR}/test"
29
+ end
30
+
31
+ #puts "#{commit_sha}: #{commit_msg}"
32
+
33
+ #
34
+ # Create a directory to hold the lolimages
35
+ #
36
+ if not File.directory? loldir
37
+ FileUtils.mkdir_p loldir
38
+ end
39
+
40
+ #
41
+ # SMILE FOR THE CAMERA! 3...2...1...
42
+ # We're just assuming the captured image is 640x480 for now, we may
43
+ # need updates to the imagesnap program to manually set this (or resize)
44
+ # if this changes on future mac isights.
45
+ #
46
+ puts "*** Preserving this moment in history."
47
+ snapshot_loc = "#{loldir}/tmp_snapshot.jpg"
48
+ system("imagesnap -q #{snapshot_loc}")
49
+
50
+ #
51
+ # Process the image with ImageMagick to add loltext
52
+ #
53
+
54
+ # read in the image, and resize it via the canvas
55
+ canvas = ImageList.new("#{snapshot_loc}")
56
+ if (canvas.columns > 640 || canvas.rows > 480)
57
+ canvas.resize_to_fill!(640,480)
58
+ end
59
+
60
+ # create a draw object for annotation
61
+ draw = Magick::Draw.new
62
+ draw.font = "/Library/Fonts/Impact.ttf"
63
+ draw.fill = 'white'
64
+ draw.stroke = 'black'
65
+
66
+ # convenience method for word wrapping
67
+ # based on https://github.com/cmdrkeene/memegen/blob/master/lib/meme_generator.rb
68
+ def word_wrap(text, col = 28)
69
+ wrapped = text.gsub(/(.{1,#{col + 4}})(\s+|\Z)/, "\\1\n")
70
+ wrapped.chomp!
71
+ end
72
+
73
+ draw.annotate(canvas, 0, 0, 0, 0, commit_sha) do
74
+ self.gravity = NorthEastGravity
75
+ self.pointsize = 32
76
+ self.stroke_width = 2
77
+ end
78
+
79
+ draw.annotate(canvas, 0, 0, 0, 0, word_wrap(commit_msg)) do
80
+ self.gravity = SouthWestGravity
81
+ self.pointsize = 48
82
+ self.interline_spacing = -(48 / 5)
83
+ self.stroke_width = 2
84
+ end
85
+
86
+ #
87
+ # Squash the images and write the files
88
+ #
89
+ #canvas.flatten_images.write("#{loldir}/#{commit_sha}.jpg")
90
+ canvas.write("#{loldir}/#{commit_sha}.jpg")
91
+ FileUtils.rm("#{snapshot_loc}")
92
+
93
+ #if in test mode, open image for inspection
94
+ if Choice.choices[:test]
95
+ system("open #{loldir}/#{commit_sha}.jpg")
96
+ end
97
+
98
+
99
+ end
100
+
101
+ end
@@ -0,0 +1,3 @@
1
+ module Lolcommits
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "lolcommits/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "lolcommits"
7
+ s.version = Lolcommits::VERSION
8
+ s.authors = ["Matthew Rothenberg"]
9
+ s.email = ["mrothenberg@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Capture webcam image on git commit}
12
+ s.description = %q{Capture webcam image on git commit for lulz}
13
+
14
+ s.rubyforge_project = "lolcommits"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency "rmagick"
25
+ s.add_runtime_dependency "git"
26
+ s.add_runtime_dependency "choice", ">= 0.1.6"
27
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolcommits
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthew Rothenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rmagick
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: git
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: choice
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.6
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.6
62
+ description: Capture webcam image on git commit for lulz
63
+ email:
64
+ - mrothenberg@gmail.com
65
+ executables:
66
+ - lolcommits
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - README.md
73
+ - Rakefile
74
+ - bin/lolcommits
75
+ - lib/lolcommits.rb
76
+ - lib/lolcommits/version.rb
77
+ - lolcommits.gemspec
78
+ homepage: ''
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project: lolcommits
98
+ rubygems_version: 1.8.21
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Capture webcam image on git commit
102
+ test_files: []