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 / 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
@lporras
lporras / puma_rails_heroku.rb
Created November 5, 2012 02:11 — forked from subelsky/puma_rails_heroku.rb
Setting up Puma and Rails on Heroku
# Gemfile
gem "puma"
# Procfile
web: bundle exec puma -p $PORT -e $RACK_ENV -C config/puma.rb
# add to config block config/environments/production.rb
config.threadsafe!
# get rid of NewRelic after_fork code, if you were doing this:
@lporras
lporras / Gemfile
Created December 17, 2012 14:22 — forked from guilleiguaran/Gemfile
source :rubygems
gem 'rails', github: 'rails/rails'
gem 'activerecord-deprecated_finders', github: 'rails/activerecord-deprecated_finders'
gem 'journey', github: 'rails/journey'
@lporras
lporras / wpautop.rb
Last active December 17, 2015 08:28 — forked from goofmint/wpautop for ruby
def wpautop(pee, br = true)
return '' if pee.strip == ''
pee = "#{pee}\n" # just to make things a little easier, pad the end
pee = pee.gsub(/<br \/>\s*<br \/>/, "\n\n")
# pace things out a little
allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
pee = pee.gsub(Regexp.new('(<'+allblocks+'[^>]*>)'), "\n"+'\1')
pee = pee.gsub(Regexp.new('(<\/'+allblocks+'[^>]*>)'), '\1' + "\n\n")
pee = pee.gsub(/\r\n|\r/, "\n") # cross-platform newlines
if pee.include?('<object')