Created
March 9, 2011 16:30
-
-
Save koyachi/862492 to your computer and use it in GitHub Desktop.
256 important things(http://www.flickr.com/photos/kylemcdonald/sets/72157625874470177/with/5426274157/)
This file contains hidden or 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
// google chrome + dotjs | |
$(document).click(function(e){ | |
// var x = e.screenX + e.clientX; | |
// var y = e.screenY + e.clientY; | |
var x = e.screenX; | |
var y = e.screenY; | |
// alert('click!' + x + ':' + y); | |
$.getJSON('http://localhost:9876/mouse?x=' + x + '&y=' + y + '&callback=?', function(msg){ | |
alert('done: ' + msg); | |
}) | |
}); |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
#filename = "chrome_mouse_#{Time.now.strftime('%Y-%m-%d-%H%M%S')}.png" | |
i = 0 | |
content_html = Dir.glob('*.png').sort.map do |file| | |
html = "<img src=\"./#{file}\" />" | |
i = i + 1 | |
if i % 8 == 0 | |
html += '<br>' | |
end | |
html | |
end.join('') | |
html = <<"HTML" | |
<html> | |
<head> | |
<title>8x8 Important Things</title> | |
</head> | |
<body> | |
<div>#{content_html}</div> | |
</body> | |
</html> | |
HTML | |
puts html | |
# result example | |
# http://gyazo.com/d61adc37489bd13eec43267ca8d604f6.png |
This file contains hidden or 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
#!/usr/local/bin/macruby | |
# -*- coding: utf-8 -*- | |
# | |
# 256 Important Things | |
# http://www.flickr.com/photos/kylemcdonald/sets/72157625874470177/with/5426274157/ | |
# | |
# code via | |
# - capture: http://d.hatena.ne.jp/Watson/20100413/1271109590 | |
# - webrick: http://d.hatena.ne.jp/Watson/20100922/1285110945 | |
# | |
framework 'Cocoa' | |
framework 'ApplicationServices' | |
# 無限大になるような範囲で適当に定義 | |
CGRectInfinite = CGRect.new([-2.0e+500, -2.0e+500], [2.0e+500, 2.0e+500]) unless defined?(CGRectInfinite) | |
class ScreenCapture | |
class << self | |
def capture(filename=nil, capture_rect=CGRectInfinite) | |
filename ||= "#{Time.now.strftime('%Y-%m-%d-%H%M%S')}.png" | |
rect = NSScreen.mainScreen.frame() | |
window = NSWindow.alloc.initWithContentRect(rect, | |
styleMask:NSBorderlessWindowMask, | |
backing:NSBackingStoreNonretained, | |
defer:false) | |
contentView = window.contentView() | |
image = CGWindowListCreateImage(capture_rect, KCGWindowListOptionOnScreenOnly, KCGNullWindowID, KCGWindowImageDefault) | |
save(image, filename) | |
end | |
def save(image, filename) | |
bitmapRep = NSBitmapImageRep.alloc.initWithCGImage(image) | |
blob = bitmapRep.representationUsingType(NSPNGFileType, properties:nil) | |
blob.writeToFile(filename, atomically:true) | |
end | |
private :save | |
def dump_mouse | |
point = NSEvent.mouseLocation() | |
puts point.x | |
puts point.y | |
end | |
def capture_mouse | |
point = NSEvent.mouseLocation() | |
rect = NSScreen.mainScreen.frame() | |
rect_around_mouse = CGRect.new([point.x, rect.size.height - point.y], [32, 32]) | |
filename = "mouse_#{Time.now.strftime('%Y-%m-%d-%H%M%S')}.png" | |
capture(filename, rect_around_mouse) | |
end | |
end | |
end | |
app = NSApplication.sharedApplication | |
#screenCapture = ScreenCapture.new | |
#screenCapture.capture() | |
# | |
#screenCapture.dump_mouse | |
#screenCapture.capture_mouse | |
require 'webrick' | |
PORT = 9876 | |
SERVER_NAME = 'capture_server' | |
server = WEBrick::HTTPServer.new( | |
:BindAddress => 'localhost', | |
:Port => PORT, | |
) | |
class Handler < WEBrick::HTTPServlet::AbstractServlet | |
def do_GET(req, res) | |
puts 'get' | |
puts "#{req.query['x']}, #{req.query['y']}" | |
offset = -16 | |
x = req.query['x'].to_i #- 600 | |
y = req.query['y'].to_i #- 300 | |
x = (x + offset < 0) ? 0 : x + offset | |
y = (y + offset < 0) ? 0 : y + offset | |
puts "#{x}, #{y}" | |
rect_around_mouse = CGRect.new([x, y], [32, 32]) | |
filename = "chrome_mouse_#{Time.now.strftime('%Y-%m-%d-%H%M%S')}.png" | |
ScreenCapture.capture(filename, rect_around_mouse) | |
end | |
end | |
server.mount("/mouse", Handler) | |
trap("INT") { server.shutdown } | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment