Skip to content

Instantly share code, notes, and snippets.

View MikeRogers0's full-sized avatar
🚂

Mike Rogers MikeRogers0

🚂
View GitHub Profile
@MikeRogers0
MikeRogers0 / uptime-monitor.sh
Last active January 30, 2024 08:52
Uptime monitoring geeklet script
#!/usr/bin/php
<?php
# Array of the servers you want to ping.
$servers = array('mikerogers.io', 'google.com', 'downserver.come');
# PingDomain() from http://stackoverflow.com/a/9843251/445724
function pingDomain($domain){
$start_time = microtime(true);
$file = @fsockopen ($domain, 80, $errno, $errstr, 10);
$end_time = microtime(true);
<?php
echo file_get_contents('http://tinyurl.com/api-create.php?url='.'http://www.example.com/');
/* For example
http://tinyurl.com/api-create.php?url=http://www.fullondesign.co.uk/
Would return:
http://tinyurl.com/d4px9f
*/
?>
@MikeRogers0
MikeRogers0 / essential-brew.sh
Last active June 23, 2023 18:17
Extra functions I like to run after running https://gist.github.com/BenNunney/7219538
#!/usr/bin/env sh
#
# Things I normally install when I first install Homebrew / Homebrew cask
# Make sure you've install XCode commandline tools & accepted the terms and conditions before running this.
# Homebrew stuff
## A nice text editor (Will show how to configure in another post)
brew install vim
brew install macvim
@MikeRogers0
MikeRogers0 / shorten.php
Created June 16, 2012 16:54
Shorten URLs using the Google URL Shortener and PHP
<?php
// Coded by Mike Rogers (http://www.fullondesign.co.uk/) 1st October 2010.
function shorten($url, $qr=NULL){
if(function_exists('curl_init')){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://goo.gl/api/shorten');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'security_token=null&url='.urlencode($url));
@MikeRogers0
MikeRogers0 / validate-email.php
Created June 16, 2012 17:09
How to validate an email address with PHP
<?php
function validEmail($email){
// Check the formatting is correct
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
return FALSE;
}
// Next check the domain is real.
$domain = explode("@", $email, 2);
return checkdnsrr($domain[1]); // returns TRUE/FALSE;
@MikeRogers0
MikeRogers0 / aoc_2020_day_16_part_two.rb
Created December 16, 2020 14:15
Advent Of Code - Day 16: Part 2
@section = File.open('input.real.txt').read.split("\n\n").compact
# Get all the rules as ranges (e.g. 0..3), with their names.
@rules = @section[0]
.split("\n")
.collect { |line|
line.scan(/(.+): ([0-9\-]+)-([0-9]+) or ([0-9\-]+)-([0-9]+)/ism).flatten
}
.collect { |name, start_range_1, end_range_1, start_range_2, end_range_2|
{
@MikeRogers0
MikeRogers0 / aoc_2020_day_16_part_one.rb
Created December 16, 2020 14:14
Advent Of Code - Day 16: Part 1
@section = File.open('input.real.txt').read.split("\n\n").compact
# Get all the rules as ranges (e.g. 0..3)
@rules = @section[0]
.scan(/([0-9\-]+)-([0-9]+)/im)
.collect { |start_range, end_range| (start_range.to_i..end_range.to_i) }
# Get all the numbers on the nearby tickets
@nearby_ticket_numbers = @section[2]
.gsub("nearby tickets:\n", '')
@MikeRogers0
MikeRogers0 / aoc_2020_day_15.rb
Created December 15, 2020 11:02
Advent of code 2020 Day 15
@input = [0,12,6,13,20,1,17]
@numbers = {}
@input.each_with_index do |input, index|
@numbers[input] = { count: 1, last_spoken_on: index + 1, last_spoken_before_on: nil }
end
@last_number_spoken = @input.last
@turn_count = @input.length + 1
@MikeRogers0
MikeRogers0 / aoc_2020_day_12_part_two.rb
Last active December 13, 2020 12:05
AOC 2020 - Day 12, part 2
class Ship
def initialize
@x = 0
@y = 0
@waypoint_x = 10
@waypoint_y = 1
end
def rotate!(direction, degrees_to_turn)
puts "Waypoint was: #{current_waypoint}"
@rows = {}
File.open('input.real.txt').read.split("\n").compact.each_with_index do |row, index|
@rows[index] = {}
row.each_char.with_index do |element, element_index|
@rows[index][element_index] = element
end
end
@last_row = @rows.keys.last
@last_column = @rows[0].keys.last