Skip to content

Instantly share code, notes, and snippets.

@jonstorer
Last active December 17, 2015 17:19
Show Gist options
  • Save jonstorer/5644691 to your computer and use it in GitHub Desktop.
Save jonstorer/5644691 to your computer and use it in GitHub Desktop.
They seem me trollin' they hatin'
rvm use system
{
"on": true,
"schedule": [
"10:13 AM",
"11:38 AM",
"1:36 PM",
"1:42 PM",
"4:52 PM",
"5:20 PM"
],
"urls": [
"http://tojohnmayerwithlove.com/",
"https://www.facebook.com/pages/John-Mayer-is-God/101509036572394",
"http://johnmayer.com/",
"http://johnmayerfans.net/",
"http://fuckyeahjohnmayer.tumblr.com/",
"http://jmayer-fanfic.livejournal.com/",
"http://johnmayer.yuku.com/topic/7705#.UZ-VOWQ4XUk",
"http://www.thebuzzmedia.com/wp-content/uploads/2008/05/john-mayer-amazing-lover.jpg",
"http://tojohnmayerwithlove.com/wp-content/uploads/2013/05/John-Mayer-Brazil-Arena-Anhembi-19-De-Setembro-.png",
"http://fc07.deviantart.net/fs19/f/2007/294/8/8/John_Mayer_2_by_h_nguyen.png",
"http://jun1013.files.wordpress.com/2009/11/john-mayer-battle-studies-album-cover.jpg",
"http://cardinalplaylists.files.wordpress.com/2012/07/john_mayer_006.jpg",
"http://i.crackedcdn.com/phpimages/article/3/8/9/144389.jpg?v=1",
"http://s3-ak.buzzfeed.com/static/campaign_images/webdr01/2012/12/30/17/heres-a-photo-of-john-mayer-in-a-santa-suit-1-31541-1356908377-1_big.jpg"
]
}
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'time'
require 'logger'
class Troll
def initialize(options)
log('run at') { Time.now }
log('system:who') { system('whoami') }
log ('ticks:who') { `whoami` }
@options = parse_options(options)
end
def run!
log('start') { "open #{url}" }
output = system("open #{url}")
log('output') { output }
log('end') { "open #{url}" }
end
def update!
command = 'git pull'
log('start') { command }
output = system command
log('output') { output }
log('end') { command }
end
def should_run?
res = run? && time_to_run?
log('should run') { res }
res
end
def should_update?
res = run? && Time.now.min % 5 == 0
log('should update') { res }
res
end
def log(msg, &block)
msg = "#{msg}#{15.times.map{' '}.join}".slice(0,15)
logger.info msg, &block
end
private
def logger
@logger ||= Logger.new(File.open('./out.log', 'a+'), 10, 1024000)
end
def run?
@options['on']
end
def time_to_run?
@options['schedule'].any? do |time|
time.between?(one_minute_ago, one_minute_from_now)
end
end
def one_minute_ago
Time.now - 60
end
def one_minute_from_now
Time.now + 60
end
def url
@options['urls'].shuffle.last
end
def parse_options(options)
options['schedule'] = options['schedule'].map {|t| Time.parse(t) }
options
end
end
begin
file = File.open('./config.json', 'r')
@troll = Troll.new JSON.parse file.read
file.close
@troll.update! if @troll.should_update?
@troll.run! if @troll.should_run?
rescue Exception => e
puts e
puts e.backtrace.join("\n")
@troll.log('exception') { e }
e.backtrace[0..10].each do |line|
@troll.log('exception') { line }
end
end
@yodarjun
Copy link

dont call the file john_mayer if you dont want it to be obvious. call it something like system_file.rb

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