Skip to content

Instantly share code, notes, and snippets.

View merqlove's full-sized avatar

Alexander Merkulov merqlove

View GitHub Profile
@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' }
# Karma configuration
# Generated on Tue Aug 20 2013 16:26:25 GMT-0400 (EDT)
module.exports = (config) ->
config.set
# base path, that will be used to resolve all patterns, eg. files, exclude
basePath: '..'
# frameworks to use
describe('e2e: main', function() {
var ptor;
beforeEach(function() {
browser.get('/');
ptor = protractor.getInstance();
});
it('should load the home page', function() {
@merqlove
merqlove / OrganizationsRoute.coffee
Last active August 29, 2015 14:05
Angular NgRoute UrlFor helper via Directive
'use strict';
angular.module('app.routes', ['ngRoute', 'app.config'])
.config(['$routeProvider', 'ROUTES', ($routeProvider, ROUTES) ->
$routeProvider
# Organizations
.when(ROUTES.organizations, {
templateUrl: '/templates/organizations/index.html',
@merqlove
merqlove / routes.coffee
Created August 18, 2014 06:54
Global Resolve for Angular ngRoute
'use strict';
angular.module('app.routes')
.config(['$routeProvider', ($routeProvider) ->
angular.extend({}, $routeProvider, {
orgWhen: (path, route) ->
route.resolve ||= {}
route.resolve = _.merge(route.resolve, {
chef: 'OrganizationCheckerProvider'
@merqlove
merqlove / DataBagService.coffee
Last active August 29, 2015 14:05
AngularJS service to work with Chef DataBags via Knife CLI.
'use strict';
class DataBagService
_exec = {}
_tmp = {}
_fs = {}
_knife = ''
constructor: (@$q) ->
console.log 'DataBagService: constructor called'