Skip to content

Instantly share code, notes, and snippets.

View chatman-media's full-sized avatar
🎯
Focusing

Alexander Kireyev chatman-media

🎯
Focusing
View GitHub Profile
class TestController < ApplicationController
before_action :authenticate_user!
def custom
render text: 'response'
end
end
describe TestController do
describe "authenticate_user!" do
@chatman-media
chatman-media / app.go
Created April 3, 2014 02:02
martini simple server
package main
import (
"github.com/go-martini/martini"
"github.com/martini-contrib/render"
"runtime"
)
type myClassic struct {
*martini.Martini
@chatman-media
chatman-media / diff
Last active August 29, 2015 13:58
Ruby frameworks bench
jruby-1.7.12
puma -e production -t 100:100 <framework>.ru
wrk -t4 -c100 -d2s http://0.0.0.0:9292/
Ruby
Rack: 17800.91
Hobbit: 15742.50
Cuba: 14828.45
JRuby + Rack + Torqbox ~ 60k req/s
myApp.controller "AccountController", AccountController = ($scope, $cookies, $log, $location, authenticationService, toaster, userService) ->
$scope.login = (userData, loginForm) ->
if loginForm.$valid
authenticationService.login(userData, $scope.antiForgeryToken).success((response) ->
if response.status
userService.user.username = response.data.userName
userService.user.isLogged = response.data.isLogged
toaster.pop "success", "You are signed in!", "", 2000, true
$location.path "/MembersPage"
else
@chatman-media
chatman-media / gist:9766028
Created March 25, 2014 16:44
JsonApiHelpers
module JsonApiHelpers
def json_response
@json_response ||= JSON.parse(response.body)
end
end
RSpec.configure do |config|
config.include JsonApiHelpers, type: :controller
end
@chatman-media
chatman-media / auth_service.rb
Last active August 29, 2015 13:57
Simple OAuth authorisation with multiply providers
class AuthService
def self.authorize(auth_data)
provider = Provider.find_or_create_by(name: auth_data['name'], uid: auth_data['uid'])
if provider.user.present?
provider.user
else
user = User.find_or_create_with_oauth(auth_data['info'])
provider.update(user: user)
user
@chatman-media
chatman-media / Specification
Last active August 29, 2015 13:57
ApplicationController spec (rspec syntax)
ApplicationController
current_user
when current_user already assigned
returns it without calling db
when current_user is nil
and user_id stores in session
finds and returns it from db
and user_id doesn't exists in session
returns nil
signed_in?
@chatman-media
chatman-media / gist:9677571
Last active August 29, 2015 13:57
guard rspec error
Error log
05:04:08 - INFO - Running: spec/models/identity_spec.rb
05:04:08 - ERROR - Guard::RSpec failed to achieve its <run_on_modifications>, exception was:
> [#] NoMethodError: undefined method `parse_options' for #<RSpec::Core::ConfigurationOptions:0x007fad670937a8 @args=[]>
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:33:in `_rspec_formatters'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:29:in `_visual_formatter'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:21:in `_parts'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/command.rb:14:in `initialize'
> [#] /Users/alder/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/guard-rspec-4.2.2/lib/guard/rspec/runner.rb:39:in `new'
@chatman-media
chatman-media / gist:9568099
Last active August 29, 2015 13:57
convert fb2 to html
module ConvertingTool
extend ActiveSupport::Concern
def self.convert(file_path)
# TODO: make schema file cache
schema_path = Rails.root.join('data', 'schemes', 'FB2_2_html.xsl')
require 'nokogiri'
@chatman-media
chatman-media / gist:8167584
Created December 29, 2013 04:53
Dynamo installation error
➜ dynamo git:(master) MIX_ENV=test mix do deps.get, test
* Getting mimetypes (git://github.com/spawngrid/mimetypes.git)
Cloning into '/Users/alder/Projects/Testing/elixir/dynamo/deps/mimetypes'...
remote: Reusing existing pack: 189, done.
remote: Total 189 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (189/189), 150.75 KiB | 103.00 KiB/s, done.
Resolving deltas: 100% (93/93), done.
Checking connectivity... done.
* Getting cowboy (git://github.com/extend/cowboy.git)
Cloning into '/Users/alder/Projects/Testing/elixir/dynamo/deps/cowboy'...