Skip to content

Instantly share code, notes, and snippets.

View fcoury's full-sized avatar

Felipe Coury fcoury

View GitHub Profile

Keybase proof

I hereby claim:

  • I am fcoury on github.
  • I am fcoury (https://keybase.io/fcoury) on keybase.
  • I have a public key whose fingerprint is 9D30 8412 6689 783E B2CD 4617 1235 3BD4 2350 E2FD

To claim this, I am signing this object:

@fcoury
fcoury / gist:542adb603e221ef82516
Last active August 29, 2015 14:06
Using React.js with Rails

I recently took over a Rails 4.1 project that was in bad shape and part of the problem is that it was using jQuery spaghetti-style code all over. Fixing the bugs in the messy code wasn't something I was really looking forward to.

My natural approach for JavaScript intensive Rails apps that I start from scratch is to use AngularJS, that I love and use already for a handful of projects.

Problem is that I usually go the all-or-nothing way when using AngularJS and Rails. I definitely wouldn't like mixing jQuery with AngularJS in this project.

I have been reading about React.js for quite a while and even played with it a little bit, but nothing too serious. After researching on how people were using React.js in Rails apps, I found two projects that make it a lot more convenient: react-rails and sprockets-coffee-react.

Rails-react

echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.3 postgresql-server-dev-9.3 postgresql-contrib-9.3 -y
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
sudo su - postgres -c "psql template1 -p 5433 -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
sudo su - postgres -c "service postgresql stop"
sudo su - postgres -c '/usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"'
require 'maruku' # or use config.gem "maruku" in environment.rb
module ApplicationHelper
# Replacement for Rails' default Markdown helper which uses Maruku instead
# of BlueCloth.
def markdown(text)
text.blank? ? "" : Maruku.new(text).to_html
end
end
@fcoury
fcoury / build_ruby19.sh
Created February 18, 2009 20:59 — forked from postmodern/build_ruby19.sh
Shameless copy of the script to deploy ruby 1.9 alonside with 1.8
#!/bin/sh
mkdir -p /usr/local/src && cd /usr/local/src
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.bz2
tar -xjvf ruby-1.9.1-p0.tar.bz2
cd ruby-1.9.1-p0
./configure --prefix=/usr --program-suffix=19 --enable-shared
make && make install
require 'rubygems'
require 'sinatra'
get '/' do
"Hello from Sinatra running on Java!"
end
require 'ostruct'
def objectify(val)
if val.is_a?(Hash)
result = {}
val.each_pair { |k,v| result[k] = objectify(v) }
result = OpenStruct.new(result)
elsif val.is_a?(Array)
result = []
val.each { |v| result << objectify(v) }
config = {}
group = nil
File.foreach("#{ENV['HOME']}/.gitconfig") do |line|
line.strip!
if line[0] != ?# and line =~ /\S/
if line =~ /^\[(.*)\]$/
group = $1
else
key, value = line.split("=")
# NAME: recaptcha
# VERSION: 1.0
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ]
# DESCRIPTION: Sinatra plugin to provide CAPTCHA support through recaptcha.net
# COMPATIBILITY: 0.3.2 /and/ latest rtomayko Hoboken builds!
# LICENSE: Use for what you want, just don't claim full credit unless you make significant changes
#
# INSTRUCTIONS:
# 0. Check out an extended client code example at the footer of this file
# 1. Ensure _this_ file is lib/recaptcha.rb within your app's directory structure
require 'time'
class PeriodicExecutor
attr_reader :next_time_to_run
def initialize(secs, &block)
@secs = secs
@block = block
@next_time_to_run = Time.now.to_f