Skip to content

Instantly share code, notes, and snippets.

require 'active_model/validator'
# Runs [Array] type validations
class ArrayValidator < ActiveModel::EachValidator
# Checks if the value is an [Array] type
#
# Will sort, remove duplicates and blanks as well.
#
# Will validate the subset if passed options are present under `subset_of`.
#
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "activerecord", "~> 4"
gem "pg", "0.19"
end
require "active_record"
@stas
stas / console.cap
Created December 13, 2013 16:01
Capistrano 3 console (Rails/SSH) tasks
namespace :rails do
desc 'Opens the Rails console'
task :console => ['deploy:set_rails_env'] do
on primary fetch(:migration_role) do
within release_path do
with rails_env: fetch(:rails_env) do
cmd_string = command(:rails, 'console').to_command
exec 'ssh %s -l %s -p %s -t "%s"' % [
host.hostname, host.username, host.port, cmd_string]
end
@stas
stas / deploy.rb
Created January 15, 2013 15:34
Mina Deploy Task (Rails + Puma + Delay Job + rbenv)
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
# require 'mina/rvm' # for rvm support. (http://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
@stas
stas / pry.rb
Created January 9, 2013 18:50
3.2.11 routing spec debugged
pry(#<RSpec::Core::ExampleGroup::Nested_14::Nested_1>)> @routes.router
=> #<Journey::Router:0xa4e6150
@options=
{:parameters_key=>"action_dispatch.request.path_parameters",
:request_class=>ActionDispatch::Request},
@params_key="action_dispatch.request.path_parameters",
@request_class=ActionDispatch::Request,
@routes=
#<Journey::Routes:0xa4e61b4
@ast=
@stas
stas / Rakefile
Created November 22, 2012 15:51
Rails Engine: rake task and generator to DRY `spec/dummy`
#!/usr/bin/env rake
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec => :dummy_app) do |t|
t.pattern = File.expand_path('../spec/**/*_spec.rb', __FILE__)
end
task :default => :spec
desc 'Generates a dummy app for testing'
task :dummy_app => [:setup, :migrate]
@stas
stas / .gitconfig
Created October 10, 2012 09:51
WordPress Git SVN config example
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
autocrlf = false
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:Courseware/buddypress-courseware.git
[branch "master"]
@stas
stas / git-version.php
Created October 5, 2012 12:59
Hook git repo version into WordPress <head>.
<?php
/*
Plugin Name: Git Version
Plugin URI: http://wordpress.org/extend/plugins/git-version/
Description: Add a git version meta to HEAD
Version: 0.1
Author: sushkov
Author URI: http://wordpress.org/extend/plugins/git-version/
*/
?>
@stas
stas / vbSEO_cowboys_should_read_php_specs.diff
Created October 1, 2012 21:24
NGINX vbSEO https/http fix.
diff --git vbseo/includes/functions_vbseo_pre.php vbseo/includes/functions_vbseo_pre.php
index db03f74..27a251f 100755
--- vbseo/includes/functions_vbseo_pre.php
+++ vbseo/includes/functions_vbseo_pre.php
@@ -26,7 +26,7 @@ if (!defined('VBSEO_VB_EXT'))
define('VBSEO_VB_EXT', 'php');
function vbseo_is_https()
{
-return isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'off') || isset($_SERVER['HTTP_FRONT_END_HTTPS']);
+return isset($_SERVER['HTTPS']) && ( !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != 'off') || isset($_SERVER['HTTP_FRONT_END_HTTPS']);
@stas
stas / config.ru
Created August 13, 2012 21:03
Rack app for serving static files (ex. on Heroku), handles haml if any, just drop it in compass project dir.
require 'haml'
# Do not buffer output
$stdout.sync = true
# Get working dir, fixes issues when rackup is called outside app's dir
root_path = Dir.pwd
use Rack::Static,
:urls => ['/stylesheets', '/images', '/javascripts', '/fonts'],
:root => root_path