Skip to content

Instantly share code, notes, and snippets.

View tpett's full-sized avatar

Travis Petticrew tpett

View GitHub Profile
@tpett
tpett / notifo
Created April 16, 2011 00:03
Ruby script to send yourself Notifo notifications with the 'notifo' gem
#!/usr/bin/env ruby
##
# notifo -- A simple Ruby script to send yourself a push notification via Notifo
#
# Usage:
#
# 1. Create a Notifo account (if you don't already have one) at notifo.com
# 2. Create a ~/.notifo file in the format NOTIFO_USERNAME:API_PASSWORD
# 3. $ gem install notifo
@tpett
tpett / beginner-player.rb
Last active December 22, 2015 10:10
Player objects for the RubyWarrior game. Includes both the beginner and intermediate versions.
class Player
attr_reader :warrior, :spaces
MAX_HP = 20
RETREAT_HP = 10
def play_turn(warrior)
set_state(warrior)
if @retreating
@tpett
tpett / README.md
Last active December 24, 2015 10:19
An example of access level based authorization with CanCan.

This is an approach to handling tiered access levels within the CanCan gem. The user inherits access grants for all levels up to and including their granted access level. This implementation assumes a User class of some kind with a method called access_level that returns the appropriate AccessLevel instance for the current user. The ability.rb file contains an example of the DSL that the TieredAbility class implements. Specs are included.

Any feedback is appreciated!

@tpett
tpett / urlify.rb
Created November 12, 2013 19:38
A quick and dirty script to take a list of files and clean them up for URLs
#!/usr/bin/env ruby
files = ARGV
DESTINATION_DIR = "./urlified"
GSUB_REPLACEMENTS = {
strip_unallowed_characters: [/[^A-Za-z0-9_\-.]/, '-'],
insert_dash_before_capitals: [/([^A-Z])([A-Z]+)/, '\1-\2'],
replace_separators_with_dashes: [/(_|\s+)/, '-'],
remove_duplicate_dashes: [/-+/, '-'],
@tpett
tpett / README.md
Last active August 29, 2015 14:00
Journey API Definition

Journey API Proposed Spec

This document describes the functionality of a Join The Journey API that will be used by a mobile app and potentially other software to ingest the app's data. As it makes sense, this API will use the REST conventions.

Endpoints

All endpoints will be prefixed with "/api".

@tpett
tpett / init-wordpress.sh
Last active August 29, 2015 14:05
Docker Wordpress Setup
#!/bin/bash
if [ -z "$1" ]; then
echo "USAGE: init-wordpress APP_NAME"
echo " APP_NAME is the base name for the new Wordpress Docker containers"
exit 1
fi
APP_NAME=$1
@tpett
tpett / boot2docker-setup.sh
Created September 12, 2014 20:34
Setup boot2docker with host additions for VirtualBox
# I had to piece together tips from several websites to get this to work so I've pulled
# everything into one place.
# Prereqs:
# Install docker
# Install boot2docker
cd ~/.boot2docker
mv boot2docker.iso boot2docker.iso.bak
@tpett
tpett / COMMANDS
Last active September 11, 2016 19:53
insteonplm diff v1.8.3..d439425 (master as of today) (filtering irrelevant commit)
git diff v1.8.3..5a845a94e02e7cf9daf7c0a40ecbdaf898190e43 bundles/binding/org.openhab.binding.insteonplm
git diff 03b62452009363556bcecb7da8e6a97cbf92ef01..master bundles/binding/org.openhab.binding.insteonplm
@tpett
tpett / README.md
Last active May 3, 2018 17:59
Rapid UI Prototyping in Rails

This is a first pass at a rapid UI prototyping pattern within a Rails app. A few notes

  1. Create any partials you want to match to URLs in app/views/prototype
  2. Crosslink between the different partials with <a href="/widgets-list">Widgets</a> or link_to.
  3. You have access to Ruby code for generating random data or even DB calls if needed.
  4. You can also use params for tweaking title text or other minor details in each page.
@tpett
tpett / useless_number_classify.rb
Created May 9, 2020 16:52
Contrived example to show a use of Proc
# frozen_string_literal: true
def useless_number_classify(number)
if number == 5
[:five, number]
elsif number.odd?
[:odd, number]
elsif number.even?
[:even, number]
end