## blogjwa.rb
require_relative '../secrets.rb'
require 'shitpost'
require 'net/https'
require 'uri'
require 'json'
USER = 'Chef'
PASS = TL_PASS
TL_POST_URL = 'https://www.teamliquid.net'
TL_POST_PATH = '/post'
def deliver_garbage(content)
uri = URI.parse(TL_POST_URL)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
data = "content=#{content}&user=#{USER}&pass=#{PASS}"
headers = {'Content-Type'=> 'application/x-www-form-urlencoded'}
JSON.parse http.post(TL_POST_PATH, data, headers)
end
content = ShitPost.generate('poop')
puts deliver_garbage(content).inspect
## blogjudge.rb
require 'nokogiri'
require_relative '../list_of_users_i_like.rb'
XML_DOC_URL = 'http://www.teamliquid.net/GetLatestUserBlogReplies?User=Chef'
def silently_judge_replies(replies)
def judgement(name)
ARRAY_OF_USERS_I_LIKE.include?(name) ? 5 : (1 + rand(5))
end
judgements = {}
replies.each_with_index do |r, i|
judgements[r['name']] ||= []
judgements[r['name']] << { i => judgement(r['name']) }
end
judgements
end
def return_replies_hash
doc = Nokogiri::XML(open(XML_DOC_URL))
Hash.from_xml(doc.xpath('//replies').to_s)
end
replies = return_replies_hash
judgements = silently_judge_replies(replies)
puts judgements.inspect
## crontab
0 0 * * 0 /usr/local/rvm/gems/ruby-2.0.0-p353@tl/wrappers/ruby /home/dev/tl/scripts/blogjwa.rb > /home/dev/cron-debug.txt 2>&1
0 * * * * /usr/local/rvm/gems/ruby-2.0.0-p353@tl/wrappers/ruby /home/dev/tl/scripts/blogjudge.rb > /home/dev/cron-debug.txt 2>&1
#TODO: Find suitable ransom to nego new end points
Blogs > Chef |
Chef
10810 Posts
| ||
Zealously
East Gorteau22261 Posts
| ||
LightTemplar
Ireland481 Posts
| ||
Zealously
East Gorteau22261 Posts
On November 23 2015 09:13 LightTemplar wrote: Consider your assumption silently judged then. It's ok I'm a writer all I do is have my thoughts judged anyway | ||
Ilikestarcraft
Korea (South)17719 Posts
| ||
Chef
10810 Posts
2.1.3 :005 > ary = ['Zealously', 'LightTemplar', 'Zealously', 'Ilikestarcraft'] => ["Zealously", "LightTemplar", "Zealously", "Ilikestarcraft"] 2.1.3 :006 > def judgement(ary); ary.each {|n| puts "#{n} #{(1 + rand(5))}" } end => :judgement 2.1.3 :007 > judgement ary Zealously 4 LightTemplar 4 Zealously 3 Ilikestarcraft 2 Harsh. Luckily the real program accounts for ils and makes him a 5 | ||
iSometric
2221 Posts
| ||
patrick321
United States185 Posts
This made me stop for a couple minutes and see if i could break it. | ||
c3rberUs
Japan11285 Posts
for comment in comments: printf comment | ||
mantequilla
Turkey775 Posts
| ||
boxerfred
Germany8360 Posts
// todo } | ||
YourGoodFriend
United States2197 Posts
Also obligatory ewww ruby {{My language}} is so much better. | ||
amazingxkcd
GRAND OLD AMERICA16375 Posts
| ||
Danglars
United States12133 Posts
| ||
Fecalfeast
Canada11355 Posts
##Feast.rb I only really know python so I googled a lot of things for this but unless I misunderstand what the module shitpost does I think this would work | ||
Chef
10810 Posts
As a personal preference, I dislike comments which are not explaining an unusual piece of code that would make another programmer wonder why you did it a specific way. The method containing the code should generally be enough to tell you what it does. | ||
Fecalfeast
Canada11355 Posts
What does 'in scope' mean? I'm fairly green at programming and just make tools that I can't find with a simple google search. Are you saying it would be better to have a separate method for finding food, then feed that variable through chew's parameter brackets? | ||
patrick321
United States185 Posts
Critiquing his code here is like stopping a singer to correct his lyrics. | ||
Chef
10810 Posts
On November 24 2015 11:15 Fecalfeast wrote: I was writing the comments to explain to me what I wanted to program to do. I lack organization and writing things down before I can articulate them in code keeps me on track. What does 'in scope' mean? I'm fairly green at programming and just make tools that I can't find with a simple google search. Are you saying it would be better to have a separate method for finding food, then feed that variable through chew's parameter brackets? Sure, it's not problem. I like to write methods I wish existed when thinking about the top level logic of my code, and then write the methods. My bad about the scope, your methods are all in the global scope so they are accessible to one another. ex 2.1.3 :001 > def bear; puts 'bear'; end => :bear 2.1.3 :002 > def kuma; puts bear; end => :kuma 2.1.3 :003 > kuma bear In larger applications, you have to throw things into classes and modules, so that you can avoid naming collisions by polluting the global scope (you can google javascript global scope for a typical explanation). If for example you had defined method A within method B, you wouldn't be able to access method A outside method B. Similarly, if you define methods within a class, you can access them anywhere within the class, but outside the class you have to call Class.method (or if you have an instance of the class, instance.method). I'm just saying your method chew does not describe accurately enough what it does, which is find food and digest it and vomit it out. So when someone calls chew they will get the unexpected result of vomit. Really your method would be accurately called find_food_eat_it_and_vomit_it_out which is a method that seems to have a lot of responsibilities. If I wrote such a method, it would have calls to three other methods, find_food eat_food (which has chew_food and swallow_food methods) vomit_food. This way the code is more reusable, the stack trace will be easier to read, and if you need to update one of them, all your methods that use them will be updates simultaneously, instead of you having to update the same code in multiple places. Even if all you use code for is one off scripts for yourself, it might help you to build a library of methods you often need to use (which you could do a very simple require to have accessible in all your scripts, saving you some copy / pasting). Naming those methods logically will help you to remember without referencing them. | ||
endy
Switzerland8970 Posts
... Chef, how about an "Allow me to analyze your code writing" ;-) | ||
| ||