Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

This comment has been minimized.

Show comment Hide comment
@amwhalen

amwhalen Sep 11, 2015

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'])

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

This comment has been minimized.

Show comment Hide comment
@bodsch

bodsch Mar 17, 2016

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

bodsch commented Mar 17, 2016

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

@windowfinn

This comment has been minimized.

Show comment Hide comment
@windowfinn

windowfinn Mar 30, 2016

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

Owner

windowfinn commented Mar 30, 2016

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

@np422

This comment has been minimized.

Show comment Hide comment
@np422

np422 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 ...

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 ...

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