Skip to content

Instantly share code, notes, and snippets.

View merqlove's full-sized avatar

Alexander Merkulov merqlove

View GitHub Profile
@merqlove
merqlove / vagrant_berkshelf.sh
Last active December 27, 2015 02:09
Vagrant-Berkshelf plugin installation on Mac OS X 10.9.
#!/bin/bash
$ sudo vagrant plugin install vagrant-berkshelf && sudo chown -R "$USER":staff ~/.vagrant.d/*
@merqlove
merqlove / puma.rb
Last active December 28, 2015 06:39
Another one Puma shell script. Here i can set path to Puma config. Very useful for multiple environments.
# Capistrano 3 tasks for Puma
namespace :puma do
%w[start stop restart status].each do |command|
desc "#{command} puma"
task command do
on roles (:app) do
within current_path do
execute "bin/puma.sh", "#{command} -c config/puma/#{fetch(:stage)}.rb"

ruby-1.9.3 cumulative performance patch for rbenv

(I guarantee nothing. No warranty I am not responsible blah blah blah. Seems to work great for me so far. Thanks to Tyler Bird and Slayer who I forked this from.)

From merqlove:

I just made little improvement to this fix:

Now you can select Ruby BUILD via same name variable. Otherwise build version will be used by default.

#!/usr/bin/env bash
set -o errtrace
set -o errexit
facter_version=$1
puppet_version=$2
target_volume=$3
@merqlove
merqlove / app.rb
Created January 28, 2014 01:22 — forked from hendrikswan/app.rb
require 'sinatra'
require 'mongoid'
require 'json'
require "sinatra/reloader" if development?
Mongoid.load!("mongoid.yml")
class Price
include Mongoid::Document
@merqlove
merqlove / base_mailer.rb
Last active August 29, 2015 14:01
Sinatra Mailer, similar with Rails :)
module Project
module Mailers
class BaseMailer < Sinatra::Mailer::Base
default from: ENV["MAIL_FROM"] || 'localhost', content_type: 'text/html'
class << self
def feedback!(text, email = nil, name='')
mail(to: "some@example.com", subject: 'Feedback', body: text) do
reply_to "#{name}<#{email}>" if email.present?
end
@merqlove
merqlove / sinatra_schemata.rb
Last active August 29, 2015 14:02
Domain based scheme selection in Sinatra via Postgres-Schemata extension for Sequel.
before do
case env["SERVER_NAME"]
when /test\./
App.db.search_path = [:test, :public]
when /test2\./
App.db.search_path = [:test2, :public]
else
App.db.search_path = [:public]
end
end
@merqlove
merqlove / spree.js.coffee.erb
Created June 6, 2014 20:04
Rails engine JS assets route path fix from Spree
#= require jsuri
class window.Spree
@ready: (callback) ->
jQuery(document).ready(callback)
@mountedAt: ->
"<%= Rails.application.routes.url_helpers.spree_path %>"
@pathFor: (path) ->
"#{window.location.origin}#{@mountedAt()}#{path}"
@merqlove
merqlove / routes.rb
Created June 6, 2014 20:07
Spree routing share across engines and app.
module Spree
module Core
class Engine < ::Rails::Engine
def self.add_routes(&block)
@spree_routes ||= []
# Anything that causes the application's routes to be reloaded,
# will cause this method to be called more than once
# i.e. https://github.com/plataformatec/devise/blob/31971e69e6a1bcf6c7f01eaaa44f227c4af5d4d2/lib/devise/rails.rb#L14
# In the case of Devise, this *only* happens in the production env
@merqlove
merqlove / create_rails_api_request.coffee
Last active August 29, 2015 14:02
Angular $resource experience with Rails based API
# Create service for our factories. Don't blow .json extension. This is easiest path to get JSON request in AUTO mode.
angular.module("identityService", ["ngResource"])
.factory 'Identity', ($resource) ->
$resource '/api/v1/identities/:id.json',
{ id:'@id' }
# Added update via PUT
@identities.config ($resourceProvider) ->
$resourceProvider.defaults.actions.update = { method: 'PUT' }