Skip to content

Instantly share code, notes, and snippets.

@cutalion
cutalion / tray.rb
Created April 17, 2011 11:42
Allows add or remove icons to unity panel white-list, so that they can be show on unity panel
require 'rubygems'
require 'json'
def save_settings(settings)
`gsettings set com.canonical.Unity.Panel systray-whitelist "#{settings.to_json.gsub('"', "'")}"`
end
def current_settings
# ./spec/spec_helper.rb
#
# Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
#
#
# Usage:
#
# its(:updated_at) { should be_the_same_time_as updated_at }
#
#
@cutalion
cutalion / action.rb
Created July 13, 2011 14:40
action helper for rspec
#
# Put this file into spec/support/ folder.
#
# Helper +action+ allows you to write something like
#
# describe "GET index" do
# action { get :index }
#
# context 'if user signed in' do
# before { sign_in user }
# Usage
#
# class Rectangle
# include TypeCast
#
# ...
#
# attr_accessor :width, :height, :fill
# type_cast :width, :height, :method => :to_f
# type_cast :fill, :allow_nil => false, :method => lambda { |value| !!value }
@cutalion
cutalion / gist:2889295
Created June 7, 2012 15:06
Rails Meetup - June 2012. Notes

Вопросы от Ивана Линько.

  1. Интересно было бы послушать чем отличается переезд с хероку от обычного деплоя на новый сервер, если чем-то отличается.
  • перенос БД (mongodump/mongorestore)
  • изменение способа хранения настроек
  • настройка почты (Google Apps)
@cutalion
cutalion / another_controller_spec.rb
Created October 25, 2012 13:23
Similar controller specs
describe SomeController do
context "if user is not logged in" do
specify "GET 'show' should redirect to login page" do
get :show
response.should redirect_to login_path
end
specify "PUT 'update' should redirect to login page" do
put :update
response.should redirect_to login_path
@cutalion
cutalion / first_controller.rb
Created October 26, 2012 11:55
Call action from action. Is it good?
class FirstController < ApplicationController
def edit
prepare_model_for_form
end
def update
current_user.attributes = params[:user]
current_user.validates_email!
if current_user.save
@cutalion
cutalion / gaz.rb
Created October 26, 2012 12:00 — forked from alg/communal.rb
# encoding: utf-8
def gas(name = "", acct = "")
url = "http://sevgaz.com.ua/index.php?option=com_content&view=article&id=52"
data = `curl -F "afam=#{name}" -F "peracc=#{acct}" "#{url}" 2>/dev/null`
data.scan(%r{Адрес.*?<tr><td>(.*?)</td>\s*<td>\s*<strong>(.*?)</strong>}).flatten
end
def water(name = "", acct = "")
@cutalion
cutalion / carrierwave.rb
Created November 13, 2012 16:23
CarrierWave test configuration
# spec/support/carrierwave.rb
class TestStorage < CarrierWave::Storage::File
def store!(file)
end
def retrieve!(identifier)
identifier
end
end
@cutalion
cutalion / Gemfile
Created November 28, 2012 00:38
Gemfile with alphabetically sorted gems
source :gemcutter
source 'http://gems.github.com'
gem 'rails', '3.2.7'
gem 'rake', '0.9.2.2'
gem 'foreman'
gem 'sidekiq', '= 2.4.0'
gem 'sinatra', require: false
# Database and data related [Putting pg to the end because of a weird bug with Lion, pg and openssl]