Skip to content

Instantly share code, notes, and snippets.

View jmahoney's full-sized avatar

Joe Mahoney jmahoney

View GitHub Profile
#!/usr/bin/env ruby
# tumblr-backup.rb
# downloads posts and related info from your a tumblr blog
# and saves them to the filesystem
# in yaml format
# Requires Mark Wunsch's awesome tumblr gem : http://github.com/mwunsch/tumblr
require "rubygems"
require "tumblr"
require "yaml"
@jmahoney
jmahoney / libxml_active_resource.rb
Created June 1, 2011 03:32 — forked from bguthrie/libxml_active_resource.rb
A patch for ActiveResource that allows it to use LibXML to parse documents. Use to speed up ARes.
require 'libxml'
module LibXML
module XML
module Conversions
module Document
def to_hash
root.to_hash
end
end
@jmahoney
jmahoney / rvm_import_gemset
Created November 14, 2012 01:28
import a list of gems into an rvm gemset
rvm gemset import <gemfile>
cmd = '"{0}" -Idummy --video-filter scene -V dummy --no-audio --scene-height=256 --scene-width=512 --scene-format=png --scene-ratio=1 --start-time={3} --stop-time={4} --scene-prefix=thumb --scene-path="{1}" "{2}" vlc://quit'.format(vlc_path, screencap_path, video_path, start, end)
@jmahoney
jmahoney / mongrel.rb
Created February 25, 2020 12:15
simple mongrel redirecting for httparty issue #582
require 'mongrel'
require 'base64'
class BasicMongrelHandler < Mongrel::HttpHandler
attr_accessor :content_type, :custom_headers, :response_body, :response_code, :preprocessor, :username, :password
def initialize
@content_type = "text/html"
@response_body = ""
@response_code = 200
@jmahoney
jmahoney / rbenb ruby-build.md
Created February 12, 2022 02:56
Updating the versions of ruby that rbenv can see on ubuntu 20.04 LTS

When you install rbenv via apt on Ubuntu 20.4 it doesn't seem to see all the versions of ruby available

e.g this happened to me:

$ rbenv install 3.1.0
ruby-build: definition not found: 3.1.0

See all available versions with `rbenv install --list'.

If the version you need is missing, try upgrading ruby-build.
@jmahoney
jmahoney / fight.twine
Last active July 19, 2022 07:12
Fighting Fantasy combat in Twine
(set: $round to it + 1)\
## Round $round
---
=|=
You STAMINA: $stamina HITS: $hits
=|=
Opponent STAMINA: $opponent_stamina HITS: $opponent_hits
|==|
---
(set: _attack to $skill + (random: 2, 12))\
(set: $skill to 6 + (random: 1, 6))\
(set: $stamina to 12 + (random: 2, 12))\
(set: $hits to 0)\
(set: $opponent_skill to 6 + (random: 1, 6))\
(set: $opponent_stamina to 12 + (random: 2, 12))\
(set: $opponent_hits to 0)
(set: $round to 1)\
# Welcome to the Fighting Fantasy simulator
You have $skill SKILL and $stamina STAMINA. Your opponent has $opponent_skill SKILL and $opponent_stamina STAMINA.
@jmahoney
jmahoney / everyone-hides.rb
Created August 29, 2023 10:00
Find duplicated permalinks in a jekyll site
require "safe_yaml"
directory = ARGV[0]
if directory.nil?
$stderr.puts "Usage: bundle exec ruby everyone-hides.rb <directory>"
exit 1
end
permalinks = []
@jmahoney
jmahoney / kicking-television.rb
Created September 14, 2023 08:48
create and add files to a youtube playlist
require 'google/apis/youtube_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'fileutils'
def valid_youtube_id?(id)
id =~ /^[a-zA-Z0-9_-]{11}$/
end
def authorize