Skip to content

Instantly share code, notes, and snippets.

View mdchaney's full-sized avatar

Michael Chaney mdchaney

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Five Squares Puzzle Demo</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
@mdchaney
mdchaney / webpage-screenshot.rb
Created July 17, 2025 18:29
Take a picture of a web page from the command line
#!/usr/bin/env ruby
require 'ferrum'
require 'optparse'
require 'uri'
class WebScreenshotter
def initialize(options = {})
@options = {
width: 1920,
@mdchaney
mdchaney / fix_encoding.rb
Last active August 2, 2025 11:35
Fix encoding to deal with mixed UTF-8 / Latin-1
def fix_encoding(str)
# The "b" method returns a copied string with encoding ASCII-8BIT
str = str.b
# Strip UTF-8 BOM if it's at start of file
if str.byteslice(0..2) == "\xEF\xBB\xBF".b
str = str.byteslice(3..-1)
end
if str.ascii_only?