Skip to content

Instantly share code, notes, and snippets.

View danhalliday's full-sized avatar

Dan Halliday danhalliday

View GitHub Profile
@danhalliday
danhalliday / wave.rb
Last active April 19, 2018 14:27
A quick start on a BinData wrapper for WAV files
#!/usr/bin/ruby
# This is a quick skeleton of how to read a Wave file in ruby using the BinData gem.
# There are many different chunk types and bit depths that should be accounted for!
require 'rubygems'
require 'bindata'
class Wave < BinData::Record
endian :little
@danhalliday
danhalliday / aws-iam-s3-paperclip-permissions.md
Last active January 12, 2017 10:14
Minimum AWS IAM inline policy permissions for Thoughtbot Paperclip and AWS S3

Minimum AWS IAM inline policy permissions for Thoughtbot Paperclip and AWS S3:

  • s3:GetObject
  • s3:PutObject
  • s3:GetObjectAcl
  • s3:PutObjectAcl
  • s3:ListMultipartUploadParts
  • s3:AbortMultipartUpload
  • s3:ListBucket
  • s3:ListBucketMultipartUploads
@danhalliday
danhalliday / article.liquid
Last active April 19, 2018 14:22
Hack to fix heading levels in Shopify-generated article content when using a Heading 1 for the page title
<div class="article">
<h1 class="article-title">
{{ article.title }}
</h1>
<div class="article-body">
{{ article.content | replace: "<h3>", "<h4>", | replace: "<h2>", "<h3>" | replace: "<h1>", "<h2>" }}
</div>
</div>
@danhalliday
danhalliday / helper.rb
Last active April 19, 2018 14:24
Quick-and-dirty idea to prevent a last word wrapping to a new line
def prevent_ugly_wrap(string)
string.reverse.sub(" ", "&nbsp;".reverse).reverse.html_safe
end
@danhalliday
danhalliday / uuid.rb
Last active April 19, 2018 14:32
Easily create UUIDs from the terminal and get ‘em on your clipboard
require "securerandom"
uuid = SecureRandom.uuid
IO.popen("pbcopy", "w") { |f| f << uuid }
puts uuid
@danhalliday
danhalliday / paranoia.sh
Last active April 19, 2018 15:13
Quick way to check if any obvious junk has made it onto your system
#!/usr/bin/env sh
# Add your favourite suspect folders. Run every now and then.
folders=(
/Library/Frameworks
/Library/LaunchAgents
/Library/LaunchDaemons
/Library/Security/SecurityAgentPlugins
~/Library/LaunchAgents
)
@danhalliday
danhalliday / LaunchCounter.swift
Last active June 1, 2023 07:25
iOS First Launch Helper
import Foundation
/// Registers how many times an app has been launched, using UserDefaults as storage.
class LaunchCounter {
private var defaults: UserDefaults
private var defaultsKey = "launchCount"
/// Initialise, optionally with a custom UserDefaults instance
init(defaults: UserDefaults = .standard) {
@danhalliday
danhalliday / sf-rounded-mobile-safari.css
Created August 16, 2019 13:37
Use this font-family name to get SF Rounded in your WKWebViews.
body {
font-family: ".AppleSystemUIFontRounded-Regular";
}
@danhalliday
danhalliday / sitemap.xml.builder
Last active October 22, 2019 14:20
Quick-and-dirty sitemap for Middleman.
xml.instruct!
xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
sitemap.resources.select { |page| page.destination_path =~ /\.html/ && page.data.noindex != true }.each do |page|
xml.url do
modified = page.data.date ? page.data.date.to_time : Time.now
xml.loc URI.join(data.site.host, page.destination_path.chomp("index.html").chomp(".html"))
xml.lastmod modified.iso8601
xml.changefreq page.data.changefreq || "monthly"
xml.priority page.data.priority || "0.5"
end
@danhalliday
danhalliday / podcast.xml.builder
Created January 8, 2020 09:18
Quick Podcast Feed with Ruby’s Builder Gem
xml.instruct! :xml, version: "1.0"
rss_attributes = {
"version" => "2.0",
"xmlns:dc" => "http://purl.org/dc/elements/1.1/",
"xmlns:sy" => "http://purl.org/rss/1.0/modules/syndication/",
"xmlns:atom" => "http://www.w3.org/2005/Atom",
"xmlns:rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"xmlns:content" => "http://purl.org/rss/1.0/modules/content/",
"xmlns:itunes" => "http://www.itunes.com/dtds/podcast-1.0.dtd",