Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created February 22, 2014 10:30
Show Gist options
  • Save emad-elsaid/9151757 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9151757 to your computer and use it in GitHub Desktop.
share your screen on the local network
require 'socket'
require 'base64'
Refresh = 1 # seconds to refresh image on server
screen_capture_command = 'screencapture -C -x tmp.png'
image = ''
latest = Time.now
server = TCPServer.new 3000
loop do
Thread.start(server.accept) do |client|
if Time.now-latest>=Refresh
system(screen_capture_command)
latest = Time.now
File.open('tmp.png', 'rb') do |file|
image = 'data:image/png;base64,'+Base64.encode64(file.read)
end
end
client.puts '<html><head>'+
"<script>setTimeout(function(){document.location.reload();},#{Refresh*1000});</script>"+
'</head><body style="padding:0px;margin:0px;">'+
"<img src=\"#{image}\" style=\"height:100%;\"/>"+
'</body></html>'
client.close
end
end
@matiasinsaurralde
Copy link

nice

@redrick
Copy link

redrick commented Feb 22, 2014

man this is hilarious thx a lot :)

@sptq
Copy link

sptq commented Feb 22, 2014

GZ :D

@pvin
Copy link

pvin commented Feb 22, 2014

good job mann.........

@emad-elsaid
Copy link
Author

thanks :) i'm really happy that you like the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment