Skip to content

Instantly share code, notes, and snippets.

View vicentereig's full-sized avatar
🐢

Vicente Reig vicentereig

🐢
View GitHub Profile
@mikhailov
mikhailov / redis_usage.rb
Created January 18, 2010 06:52
Rails on Redis - is all about high performance
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts.all_cached # Retrive only at once by every 5 minutes
expires_in 5.minutes, :private => false, :public => true
end
end
# app/models/post.rb
Class Post
@SebastianEdwards
SebastianEdwards / gist:945263
Created April 27, 2011 21:30
Nicest way to get barista working on heroku
# Gemfile
gem "therubyracer-heroku"
# config/initializers/barista_config.rb
Barista.configure do |c|
c.root = Rails.root.join("app", "coffeescripts")
c.output_root = Rails.root.join("tmp", "javascripts")
end
require 'fileutils'
@vinioliveira
vinioliveira / Additional Commands
Created June 30, 2011 00:04
Init.d Juggernaut2 script for Ubuntu
$ sudo adduser --system --no-create-home --disabled-login --disabled-password --group juggernaut
$ sudo mv ~/juggernaut2-for-init.d-startup.sh /etc/init.d/juggernaut
$ sudo chmod +x /etc/init.d/juggernaut
$ sudo update-rc.d -f juggernaut defaults
@J-Gull
J-Gull / gist:1060167
Created July 2, 2011 13:20
Configuring Resque Web Interface in Application
#The steps need to be performed to use resque-web with in your application
#In routes.rb
ApplicationName::Application.routes.draw do
resources :some_controller_name
mount Resque::Server, :at=> "/resque"
end
#That's it now you can access it from within your application i.e
@zumbojo
zumbojo / bijective.rb
Created July 9, 2011 22:09
Simple bijective function (base(n) encode/decode)
# Simple bijective function
# Basically encodes any integer into a base(n) string,
# where n is ALPHABET.length.
# Based on pseudocode from http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/742047#742047
ALPHABET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split(//)
# make your own alphabet using:
# (('a'..'z').to_a + ('A'..'Z').to_a + (0..9).to_a).shuffle.join
@jcasimir
jcasimir / sessions_and_conversations.markdown
Created September 11, 2011 23:07
Sessions and Conversations in Rails 3

Sessions and Conversations

HTTP is a stateless protocol. Sessions allow us to chain multiple requests together into a conversation between client and server.

Sessions should be an option of last resort. If there's no where else that the data can possibly go to achieve the desired functionality, only then should it be stored in the session. Sessions can be vulnerable to security threats from third parties, malicious users, and can cause scaling problems.

That doesn't mean we can't use sessions, but we should only use them where necessary.

Adding, Accessing, and Removing Data

@ajokela
ajokela / imgscalr.rb
Created October 7, 2011 19:40 — forked from mchung/imgscalr.rb
imgscalr in jruby
require "imgscalr-lib" # https://github.com/thebuzzmedia/imgscalr
require "jruby"
java_import "javax.imageio.ImageIO"
ImageIO.write(
com.thebuzzmedia.imgscalr.Scalr.resize(
ImageIO.read(java.io.File.new("iss.jpg")),
250),
"jpg",
java.io.File.new("iss_new.jpg"))
@norman
norman / earthdistance.rb
Last active November 3, 2022 21:20
Geographic Searches With Postgres's Earthdistance and Cube Extensions
#!/usr/bin/env ruby
=begin
= Geographic Searches With Postgres's Earthdistance and Cube Extensions
This program shows how to easily create a Postgres database that uses the Cube
and Earthdistance extensions to perform fast queries on geographic data.
Briefly, the problem this code solves is "show me all places within 50
kilometers of New York City."
@ThomasBurleson
ThomasBurleson / angular-bc.js
Created February 7, 2012 22:41 — forked from vojtajina/angular-bc.js
Angular: decorates/intercepts $controller service
/**
* @license AngularJS
* (c) 2010-2012 AngularJS http://angularjs.org
* License: MIT
*/
/**
* Backward compatibility module for AngularJS
* @author Vojta Jina <vojta.jina@gmail.com>
*
@ahoward
ahoward / presenter.rb
Created February 22, 2012 23:09
worlds simplest presenter pattern. drop in replacement for ActiveRecord/Mongoid models in your controller
# the worlds lightest weight presenter pattern. to use simply
#
# file app/presenters/post_presenter.rb
#
# PostPresenter =
# Presenter.for(Post) do
# validates_presence_of :custom_field_for_this_form
#
# end
#