Skip to content

Instantly share code, notes, and snippets.

@mileszs
mileszs / gist:5575333
Created May 14, 2013 11:43
This is a (living) list of resources recommended by the Indianapolis Ruby Brigade for beginners to Ruby.
include Workflow
workflow do
state :in_progress do
event :publish, transitions_to: :awaiting_review
end
state :awaiting_review do
event :sent, transitions_to: :being_reviewed
end
@mileszs
mileszs / categories_generator.rb
Last active December 12, 2015 04:49
This is my refactored version of https://gist.github.com/mileszs/4709536. I am happier with it primarily because all of the parts are now in a single class for each major piece of functionality. It's much easier to understand; when you see in the controller `PagesGenerator.new(document).generate!`, you look in the PagesGenerator class, where you…
class CategoriesGenerator
def initialize(document, options = {})
@document = document
@master_categories = options[:master_categories] || MasterCategory.all
end
def generate!
@master_categories.each do |master_category|
@mileszs
mileszs / category.rb
Created February 4, 2013 20:36
Each document instance has categories and pages that are generated from "master categories" and "master pages". I think a refactor is in order. I would like to compare my result with the thoughts of others. How would you refactor this code (if you would refactor it)?
class Category < ActiveRecord::Base
belongs_to :document
belongs_to :master_category
has_many :pages
def generate_pages!
if pages.empty?
master_category.master_pages.each do |master_page|
pages.create!(master_page.page_attributes)
class Admin::StepsController < AdminController
include ::Wicked::Wizard
steps :categories, :pages
expose(:magnet_app)
expose(:master_categories) { MasterCategory.all }
def show
if step == :categories and magnet_app.categories.empty?
magnet_app.generate_categories!
elsif step == :pages
@mileszs
mileszs / rserv-func.sh
Created December 6, 2012 12:51
Find the next available port when starting the Rails server
function rserv()
{
rport=3000
port_taken=`lsof -i tcp:${rport}`
while [ $port_taken ]
do
echo "Port ${rport} taken..."
(( rport++ ))
port_taken=`lsof -n -i tcp:${rport}`
done
@mileszs
mileszs / gist:4131402
Created November 22, 2012 14:20
Indy.rb November 2012 Intro (using termnote)
---
type: chapter
title: Indy.rb November 2012
subtitle: Microframework Hack Night
---
type: text
title: Sponsored by...
content: |
Thanks iGoDigital!
@mileszs
mileszs / gist:4124785
Created November 21, 2012 13:13 — forked from olistik/gist:2627011
Ubuntu 12.10 setup (rbenv/rvm, janus, postgres)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
@mileszs
mileszs / gist:4081411
Created November 15, 2012 21:29
Indy.rb November 2012 Microframework Hack Night Results

We broke up into several groups, picked one out of a handful of Ruby microframeworks, and hacked together a Reddit clone - or, as much as we could build in about an hour. Below are some of the results:

Espresso

App: Dark Roast

Participants: David Jones, Timothy Barnes, Gentleman Whose Name Remains a Mystery to My Feeble Mind

Camping