Skip to content

Instantly share code, notes, and snippets.

View samnissen's full-sized avatar

Sam samnissen

  • United Kingdom
View GitHub Profile
@samnissen
samnissen / vaccine_countdown.rb
Last active January 29, 2021 20:23
Get a daily countdown to Vaccine Day UK
require 'active_support/all'
require 'HTTParty'
require 'json'
UK_CHILD_DECIMAL = 0.189
UK_ADULT_DECIMAL = 1.0 - UK_CHILD_DECIMAL
UK_POPULATION = 67_886_004.0
UK_ADULT_POPULATION = UK_POPULATION * UK_ADULT_DECIMAL
DOWNLOAD_URL = 'https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=nation&structure={"date":"date","total":"cumPeopleVaccinatedFirstDoseByPublishDate","new":"newPeopleVaccinatedFirstDoseByPublishDate"}'
# v2 is not working today (Jan. 26), and instead respondes with a
@samnissen
samnissen / c19.csv
Created March 9, 2020 16:40
Predict the number of new COVID-19 cases tomorrow
day new total
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 2 2
9 0 2
@samnissen
samnissen / watir-console-logs.rb
Created June 9, 2018 05:44
Capture / display the console log output from a page load with Watir
require 'watir'
b = Watir::Browser.new
b.goto "https://nytimes.com"
b.driver.manage.logs.get(:browser).each do |log|
puts log
end
@samnissen
samnissen / registrar.rb
Created October 17, 2017 10:10
Get WHOIS record data from both registry and registrar
require 'whois'
require 'whois-parser'
require 'addressable/uri'
require 'public_suffix'
class Registrar
class << self
def lookup(domain, timeout = 30)
tld = tld_domain(domain)
base_tld_definition = Whois::Server.definitions(:tld).map{|s| s if s[0] == tld}.compact.first
@samnissen
samnissen / net-export-with-ruby-and-watir.rb
Last active December 9, 2022 03:45
Get a HAR export of internet activity triggered by a passing a URL to a browser with Ruby and Watir-Webdriver
require 'watir-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension "/your/path/to/Firefox/profile/extensions/[email protected]"
profile.add_extension "/your/path/to/Firefox/profile/extensions/[email protected]"
profile["extensions.firebug.currentVersion"] = "2.0.14" # Supress "What's new in Firebug" tab from opening.
profile["extensions.firebug.delayLoad"] = false
profile["extensions.firebug.showFirstRunPage"] = false
profile["extensions.firebug.console.enableSites"] = true
@samnissen
samnissen / gist:c9b9ffc3c49e2b828ca5
Last active August 29, 2015 14:24
Confirming access to alerts in a StackOverflow question, take 2
#!/bin/env ruby
# encoding: utf-8
# Trying to replicate error described in a StackOverflow Question
# http://stackoverflow.com/questions/31065711/watir-webdriver-does-not-show-dialogs-in-firefox-when-finished-testing
require 'os'
require 'headless'
require 'watir-webdriver'
require 'yaml'
@samnissen
samnissen / gist:76bc20505ba93257261e
Last active August 29, 2015 14:24
Confirming access to alerts in a StackOverflow question
#!/bin/env ruby
# encoding: utf-8
# Trying to replicate error described in a StackOverflow Question
# http://stackoverflow.com/questions/31065711/watir-webdriver-does-not-show-dialogs-in-firefox-when-finished-testing
require 'os'
require 'headless'
require 'watir-webdriver'
class SammerHammer < RTanque::Bot::Brain
NAME = 'sammer_hammer'
include RTanque::Bot::BrainHelper
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0
def tick!
## main logic goes here
@desired_heading ||= nil