Skip to content

Instantly share code, notes, and snippets.

@windowfinn
Last active December 8, 2020 01:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windowfinn/f8c35551138babcc3e9e to your computer and use it in GitHub Desktop.
Save windowfinn/f8c35551138babcc3e9e to your computer and use it in GitHub Desktop.
Dashing Chuck Norris Fact Generator Job

Description

Dashing job to render personalised Chuck Norris based facts into a text widget.

This job utilises the Internet Chuck Norris Database JSON api.

A randomly chosen forename and surname from an array of team members is chosen and passed to the icnd json api, and a Chuck Norris based fact, with the Chuck and the Norris replaced with our teammembers name is returned, and then sent to a dashing widget.

Installation

Put the chuck.rb file into the /jobs directory.

Add an entry into your dashboard file - see the example.

If you need to use a proxy, populate the details in chuck.rb and comment/uncomment the appropriate res = ... line.

Some of the icnd jokes might be seen to be a bit cheeky, so use can try to limit those by altering the limitTo attribute - see the api.

require 'net/http'
require 'json'
require 'cgi'
#The Internet Chuck Norris Database
server = "http://api.icndb.com"
#Id of the widget
id = "chuck"
#Proxy details if you need them - see below
proxy_host = 'XXXXXXX'
proxy_port = 8080
proxy_user = 'XXXXXXX'
proxy_pass = 'XXXXXXX'
#The Array to take the names from
teammembers = [['Mickey','Mouse']]
SCHEDULER.every '30s', :first_in => 0 do |job|
random_member = teammembers.sample
firstName = random_member[0]
lastName = random_member[1]
#The uri to call, swapping in the team members name
uri = URI("#{server}/jokes/random?firstName=#{firstName}&lastName=#{lastName}&limitTo=[nerdy]")
#This is for when there is no proxy
res = Net::HTTP.get(uri)
#This is for when there is a proxy
#res = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).get(uri)
#marshal the json into an object
j = JSON[res]
#Get the joke
joke = CGI.unescapeHTML(j['value']['joke'])
#Send the joke to the text widget
send_event(id, { title: "#{firstName} #{lastName} Facts", text: joke })
end
...
<div data-id="chuck" data-view="Text" data-title="Team Facts" data-moreinfo="Team Member Facts.">
...
@amwhalen
Copy link

Thanks for the cool idea. I had no idea a Chuck Norris DB existed! I noticed that some HTML entities (&quot;) were showing up in the text. I was able to unescape them by using the cgi gem and modifying the joke variable:

require 'cgi'
...
joke = CGI.unescapeHTML(j['value']['joke'])

@bodsch
Copy link

bodsch commented Mar 17, 2016

i love this! :)
and i want it for our dashboard ...

@windowfinn
Copy link
Author

Cool - I'm glad it's getting some use.

@np422
Copy link

np422 commented Aug 25, 2017

Much enjoyed, thank you!

I just put it up on a dashboard I'm putting together for a client with all the employees names listed, let's see how long time it takes before one of the boring types that's working there complains ...

@mboesch
Copy link

mboesch commented Feb 14, 2019

Cool thing, thank you very much!
I'll keep it on our dashboards as long as my boss lets me. :-)

@KangoV
Copy link

KangoV commented Jul 19, 2019

Cool. We used to have this for Jenkins.

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