Skip to content

Instantly share code, notes, and snippets.

@konalegi
konalegi / gist:9544209
Last active August 29, 2015 13:57
arel study
def self.for_user(user_id, filter = {})
filter = {
:amount => nil,
:src_users => [],
:trg_users => []
}.merge(filter)
transaction = Transaction.arel_table
operation = Operation.arel_table
@konalegi
konalegi / child
Last active August 29, 2015 13:57
class @UserTypeAhead extends AngularDirective
link: (scope, element, attrs, controller) =>
@$log.debug('hello from child');
console.log('element: ',element);
App.directive 'userTypeahead', new UserTypeAhead('$log')
scope.acl = {}
return unless @user?
scope.is_authenticated = @isLogged()
scope.user = @user
for key,role of @user.roles
for resource_key, resource of window.Acl[@user.company_namespace].acl
for action_key, action of resource
if action[role]?
require 'test_helper'
require 'controllers/api/speakphone/test_helper'
class Api::Speakphone::CompaniesControllerTest < ActionController::TestCase
@acl_hash = {
admin: { index: :success , update: :success , create: :success , destroy: :success },
content_manager:{ index: :success , update: :success , create: :success , destroy: :success },
device_manager:{ index: :success , update: :unauthorized , create: :unauthorized , destroy: :unauthorized }
@konalegi
konalegi / SignUpType.rb
Created May 23, 2014 09:12
angular simple form
class SignUpType < BaseType
attribute :email, String
attribute :password, String
attribute :password_confirmation, String
attribute :name, String
attribute :surname, String
validates :email, email: true, :presence => { :message => "sign_up_type.email.presense" }
validates :password, :presence => { :message => "sign_up_type.password.presense" }
@konalegi
konalegi / application_controller.rb
Created May 26, 2014 08:16
rails api validation
rescue_from TypeExceptions::InvalidParamsError, with: :handle_invalid_params
def handle_invalid_params e
render json: e.message, status: :unprocessable_entity
end
def self.get_geo_object(fias_object)
address_encoded = URI.encode fias_object.address.strip
url = "http://geocode-maps.yandex.ru/1.x/?geocode=#{address_encoded}"
xml = Hash.from_xml(RestClient.get(url))
count = xml["ymaps"]["GeoObjectCollection"]["metaDataProperty"]["GeocoderResponseMetaData"]["found"].to_i
p url
p count
if (count > 1)
pos = xml["ymaps"]["GeoObjectCollection"]["featureMember"][0]["GeoObject"]["Point"]["pos"]
else
@konalegi
konalegi / .gitconfig
Created July 20, 2014 06:39
git settings
[color]
diff = auto
status = auto
branch = auto
interactive = auto
[diff]
renamelimit = 0
[merge]
summary = true
[alias]
ChatApp = angular.module('ChatApp', []);
ChatApp.config(function ($httpProvider) {
$httpProvider.defaults.headers.common['X-CSRF-TOKEN'] = $("meta[name=\"csrf-token\"]").attr("content");
});
ChatApp.controller('ChatController', function ($scope, $http) {
$scope.messages = [];
$scope.send = function () {
var message = $scope.new_message;
@konalegi
konalegi / error.log
Last active August 29, 2015 14:06
riak_cs logs
2014-09-23 10:45:18.710 [error] <0.149.0> Supervisor riak_cs_sup had child riak_cs_gc_d started with riak_cs_gc_d:start_link() at <0.24099.126> exit with reason no match of right hand value {error,all_workers_busy} in riak_cs_gc_key_list:gc_index_query/5 line 153 in context child_terminated
2014-09-23 11:00:18.710 [error] <0.27448.126> gen_fsm riak_cs_gc_d in state fetching_next_batch terminated with reason: no match of right hand value {error,all_workers_busy} in riak_cs_gc_key_list:gc_index_query/5 line 153
2014-09-23 11:00:18.710 [error] <0.27448.126> CRASH REPORT Process riak_cs_gc_d with 1 neighbours exited with reason: no match of right hand value {error,all_workers_busy} in riak_cs_gc_key_list:gc_index_query/5 line 153 in gen_fsm:terminate/7 line 611
2014-09-23 11:00:18.711 [error] <0.149.0> Supervisor riak_cs_sup had child riak_cs_gc_d started with riak_cs_gc_d:start_link() at <0.27448.126> exit with reason no match of right hand value {error,all_workers_busy} in riak_cs_gc_key_list:gc_index_query/5 l