Skip to content

Instantly share code, notes, and snippets.

@windowfinn
Last active December 8, 2020 01:18
Show Gist options
  • 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.">
...
@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