Skip to content

Instantly share code, notes, and snippets.

View lporras's full-sized avatar
🏠
Working from home

Luis Alfredo Porras Páez lporras

🏠
Working from home
View GitHub Profile
@lporras
lporras / syntax_highlighting.py
Created January 12, 2012 16:08 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@lporras
lporras / rails31init.md
Created April 3, 2012 20:17 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

@lporras
lporras / delegate_matcher.rb
Created April 5, 2012 13:26 — forked from txus/delegate_matcher.rb
RSpec matcher for delegations
# RSpec matcher to spec delegations.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:month).to(:created_at) }
# it { should delegate(:year).to(:created_at) }
# end
@lporras
lporras / pjax.rb
Created April 16, 2012 04:14 — forked from tjstein/pjax.rb
Pjax(pushState + Ajax) with Sinatra and BackboneJs
#encoding: UTF-8
require 'rubygems'
require 'sinatra'
require 'erb'
require 'pp'
class Sinatra::Request
def pjax?
env['HTTP_X_PJAX'] || self['_pjax']
@lporras
lporras / chat.rb
Created May 3, 2012 03:11 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@lporras
lporras / Publish a message
Created May 31, 2012 15:16 — forked from linus/Publish a message
Server-side Events with Node.js and Redis
linus@Newton:~$ redis-cli
redis 127.0.0.1:6379> publish /updates.foo "hello there!"
(integer) 1
redis 127.0.0.1:6379>
@lporras
lporras / index.html
Created June 2, 2012 12:48 — forked from brianleroux/index.html
ghetto-photoshare app logic
<!DOCTYPE html>
<html>
<body>
<script src="phonegap-1.0.0.js"></script>
<script>
function uploadPhoto(imageURI) {
function win(r) {
@lporras
lporras / gist:2878293
Created June 5, 2012 21:54 — forked from artemave/gist:1303619
custom shoulda validate_inclusion_of matcher
RSpec::Matchers.define :validate_inclusion_of do |field, list|
match do |actual|
list.each do |i|
actual.should allow_value(i).for(field)
end
end
end
@lporras
lporras / juggernaut_channels.rb
Created July 7, 2012 04:17 — forked from maccman/juggernaut_channels.rb
Sinatra Server Side Event streaming with private channels.
# Usage: redis-cli publish message.achannel hello
require 'sinatra'
require 'redis'
conns = Hash.new {|h, k| h[k] = [] }
Thread.abort_on_exception = true
get '/' do
@lporras
lporras / gist:3517680
Created August 29, 2012 19:35 — forked from joelmoss/gist:2470666
Capistrano recipe for Puma start/stop/restarts
set :shared_children, shared_children << 'tmp/sockets'
namespace :deploy do
desc "Start the application"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{stage} bundle exec puma -b 'unix://#{shared_path}/sockets/puma.sock' -S #{shared_path}/sockets/puma.state --control 'unix://#{shared_path}/sockets/pumactl.sock' >> #{shared_path}/log/puma-#{stage}.log 2>&1 &", :pty => false
end
desc "Stop the application"
task :stop, :roles => :app, :except => { :no_release => true } do