Skip to content

Instantly share code, notes, and snippets.

View glebm's full-sized avatar

Gleb Mazovetskiy glebm

View GitHub Profile
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)
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'
class NewsStory < ActiveRecord::Base
has_many :comments, :as => :commentable, :dependent => :destroy
belongs_to :user
validates_presence_of :body, :title
end
# 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.
@glebm
glebm / .bashrc
Created February 21, 2011 15:52
tee -a
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 April 18, 2011 21:21
Capistrano recipe to create a user on EC2
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 September 24, 2011 13:28
A module to invalidate cache on Amazon CloudFront
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 January 25, 2012 16:06
Sets up load paths for RVM to be used with Passenger
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 July 13, 2012 18:57 — forked from mraaroncruz/rideshare.md
Renfe AVE rideshare app

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 August 3, 2012 00:21
Unicorn /etc/init.d script for use with bundler
#!/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