Skip to content

Instantly share code, notes, and snippets.

Avatar

Gleb Mazovetskiy glebm

View GitHub Profile
View application.rb
require File.expand_path('../boot', __FILE__)
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_record/railtie"
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
View Gemfile
source :gemcutter
gem "rack"
gem "rake"
gem "rails", "~> 3", :require => nil
gem 'enumerated_attribute'
gem 'gravtastic'
gem 'devise', :git => 'http://github.com/plataformatec/devise.git'
gem 'RedCloth'
View news_story.rb
class NewsStory < ActiveRecord::Base
has_many :comments, :as => :commentable, :dependent => :destroy
belongs_to :user
validates_presence_of :body, :title
end
View script.rb
# A module which is an instance of the Script class encapsulates in its scope
# the top-level methods, top-level constants, and instance variables defined in
# a ruby script file (and its subfiles) loaded by a ruby program. This allows
# use of script files to define objects that can be loaded into a program in
# much the same way that objects can be loaded from YAML or Marshal files.
#
# See intro.txt[link:files/intro_txt.html] for an overview.
class Script < Module
# The file with which the Script was instantiated.
View .bashrc
export EDITOR=`which vim`
#-----------------------------------------------------------------------------
# Prompts
#-----------------------------------------------------------------------------
set_prompts() {
# regular colors
local DEFAULT="\[\033[0m\]" # standard terminal fg color
local BLACK="\[\033[0;30m\]"
local RED="\[\033[0;31m\]"
@glebm
glebm / bootstrap_user.rb
Created Apr 18, 2011
Capistrano recipe to create a user on EC2
View bootstrap_user.rb
set :aws_private_key_path, "~/.ec2/mrkey.pem"
namespace :setup_server do
desc "adds a user and uploads his id_rsa.pub to the EC2 instance's deploy users authorized_keys2 file"
task :create_deploy_user do
# \\n becomes \n
commands = <<-SH.split("\n").map(&:strip).join(";")
sudo echo hi
sudo groupadd admin
@glebm
glebm / cloud_front.rb
Created Sep 24, 2011
A module to invalidate cache on Amazon CloudFront
View cloud_front.rb
require 'openssl'
require 'net/http'
require 'net/https'
module CloudFront
extend self
def invalidate(path)
date = Time.now.utc
date = date.strftime("%a, %d %b %Y %H:%M:%S %Z")
@glebm
glebm / setup_load_paths.rb
Created Jan 25, 2012
Sets up load paths for RVM to be used with Passenger
View setup_load_paths.rb
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."
@glebm
glebm / rideshare.md
Created Jul 13, 2012 — forked from mraaroncruz/rideshare.md
Renfe AVE rideshare app
View rideshare.md

Renfe AVE (high speed train) rideshare app

  • There are huge discounts on purchasing 4 seats

From @glebm

I'm thinking that we could take the money upfront when you join a departure (datetime, from station, to station) The hold gets charged to a group of 4 when the group 4 if full, and the user receives a confirmation email (i18n en, es, etc. would be great) If the group is not full at N hours before departure, the money is returned, and the user is notified

We would need to get data from renfe (no api) for schedule and ticket availability

@glebm
glebm / unicorn
Created Aug 3, 2012
Unicorn /etc/init.d script for use with bundler
View unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
# Updated by glebm for newer unicorn and to use with bundle exec
#
## A sample /etc/unicorn/my_app.conf
You can’t perform that action at this time.