This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TicketsController < ApplicationController | |
def show | |
tickets = params[:tickets].split(",") | |
ticket_data = tickets.map do |ticket| | |
parallel { Faraday.get("http://tickets.local/#{ticket}") } | |
end | |
render json: { tickets: ticket_data.map(&:result) } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
def self.present as, from, klass | |
if from.to_s.singularize == from.to_s | |
expose(as) { klass.new send(from) } | |
else | |
expose(as) { send(from).map { |orig| klass.new(orig) } } | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: ft=ruby | |
source :rubygems | |
gem 'eventmachine' | |
gem 'em-zeromq', :path => '~/Work/em-zeromq' | |
gem 'sinatra' | |
gem 'zmq' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test | |
(:use overtone.live | |
;overtone.inst.synth | |
overtone.inst.io)) | |
(def a (buffer 2048)) | |
(def b (buffer 2048)) | |
(definst vocoder [freq 432] | |
(let [input (in 8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Padrino | |
# Minimal version of `decent_exposure`[1], in keeping with Padrino's | |
# simplicity. | |
# | |
# [1] https://github.com/voxdolo/decent_exposure | |
# | |
# == Usage | |
# | |
# The first step is to register the plugin with your application: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# I was asked for an example of code that was DRY, but still had an | |
# instance of Connascence of Algorithm going on. | |
# | |
# Consider the following code. I think most people would agree that | |
# the code is fairly DRY in the sense that there is no duplicated | |
# code. | |
# | |
require 'digest/sha1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileController < ActionController::Base | |
private | |
def current_user | |
@current_user ||= User.find_by_username(session[:username]) if session[:username] | |
end | |
helper_method :current_user | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql', | |
:encoding => 'utf8', | |
:database => 'foo', | |
:username => 'bar', | |
:password => 'baz', | |
:host => 'localhost' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Apply Google translate to auto translate all texts in locale ENV['FROM'] to locale ENV['TO']" | |
task :google => :environment do | |
raise "Please specify FROM and TO locales as environment variables" if ENV['FROM'].blank? || ENV['TO'].blank? | |
# Depends on httparty gem | |
# http://www.robbyonrails.com/articles/2009/03/16/httparty-goes-foreign | |
class GoogleApi | |
include HTTParty | |
base_uri 'ajax.googleapis.com' | |
def self.translate(string, to, from) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Awesomeness | |
extend ActiveSupport::Concern | |
included do | |
scope :awesome, where(:favorite_language => 'ruby') | |
end | |
module ClassMethods | |
def make_everyone_awesome | |
update_all(:favorite_language => 'ruby') |
NewerOlder