Skip to content

Instantly share code, notes, and snippets.

@xionon
xionon / Vagrantfile
Created January 31, 2014 15:36
Big old vagrantfile to spin up multiple nodes
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
NODES = [
['proxy', 1, 10],
['app', 1, 20],
['db', 1, 30],
['cache', 1, 40]
]
@xionon
xionon / regex.rb
Last active August 29, 2015 13:55
This is a runable tutorial on 3 regex tips that will make your code more readable: 1) named capture groups, 2) whitespace+comments, 3) an alternate syntax
require 'minitest'
require 'minitest/spec'
require 'minitest/autorun'
describe 'Regexes are super great' do
before do
@month = "12"
@day = "15"
@year = "2014"
@date = "#{@month}/#{@day}/#{@year}"
@xionon
xionon / gist:9916302
Created April 1, 2014 15:19
keybase.md
### Keybase proof
I hereby claim:
* I am xionon on github.
* I am alechipshear (https://keybase.io/alechipshear) on keybase.
* I have a public key whose fingerprint is 7D65 BBE1 3BD5 E1F7 891E D8A3 3586 6DC4 A359 A3E5
To claim this, I am signing this object:
# Updated by Siege 3.0.5, February-03-2014
# Copyright 2000-2013 by Jeffrey Fulmer, et al.
#
# Siege configuration file -- edit as necessary
# For more information about configuring and running
# this program, visit: http://www.joedog.org/
#
# Variable declarations. You can set variables here
# for use in the directives below. Example:
class PostsController < ApplicationController
respond_to :html, :json
before_action :find_post, only: %i(show edit update destroy)
before_action :find_posts, only: %i(index)
def index
respond_with decorate(@posts)
end
module Foo
def run
puts 'Does the thing'
end
end
class Bar
include Foo
end
class ApplicationController < ActionController::Base
# see: http://guides.rubyonrails.org/action_controller_overview.html#rescue-from
rescue_from ApiKey::NotAuthorized, with: :api_key_not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
private
# see: http://guides.rubyonrails.org/layouts_and_rendering.html#options-for-render
def record_not_found
render file: '404.html', status: :not_found
@xionon
xionon / routes.rb
Created June 9, 2014 18:51
Namespaced url, un-prefixed method
namespace 'manage', as: '' do
resources :programs
end
#----
$ rake routes
Prefix Verb URI Pattern Controller#Action
programs GET /manage/programs(.:format) manage/programs#index
POST /manage/programs(.:format) manage/programs#create
# Ensures that we can save a news item and queue up the right jobs around it
class NewsSaveService
def self.save!(news)
new(news).save!
end
def initialize(news)
@news = news
end
@xionon
xionon / gist:f946b27f27c1fbb6eaba
Created June 28, 2014 14:29
Difference between an app generated with active record and an app without active record
diff -r app-with-ar/Gemfile app-without-ar/Gemfile
6,7d5
< # Use sqlite3 as the database for Active Record
< gem 'sqlite3'
diff -r app-with-ar/Gemfile.lock app-without-ar/Gemfile.lock
97d96
< sqlite3 (1.3.9)
123d121
< sqlite3
diff -r app-with-ar/config/application.rb app-without-ar/config/application.rb