Skip to content

Instantly share code, notes, and snippets.

module Roleable
extend ActiveSupport::Concern
included do
has_many :roles, through: :user_roles
has_many :actions, through: :roles
end
end
class User
def authorized_to?(action, roleable)
roleable.actions.where(user_roles: { user_id: 1 }).count > 0 ||
user.global_actions.where(value: action).count > 0
end
private
def global_actions
user.actions.where(user_roles: { roleable_id: nil, roleable_type: nil })
2015-06-15T17:55:47Z p-21711 t-10apdg ERROR: [worker-lessons_of_interest_publisher:1:xhp9z4][#<Thread:0x000000074485e8>][lessons_of_interest_publisher][#<Sneakers::Configuration:0x00000007449ba0>] unexpected error [Exception error="could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)" error_class=ActiveRecord::ConnectionTimeoutError backtrace=/var/app/shared/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:189:in `block in wait_poll',/var/app/shared/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:180:in `loop',/var/app/shared/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:180:in `wait_poll',/var/app/shared/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:135:in `block in poll',/usr/local/rvm/rubies/ruby-2.2.0/lib/ruby
# NOTE: All model inheriting this method must implement a #publish! method.
module Publishable
def publish_to!(batch)
publish_parents!(batch)
publish_children!(batch)
end
def publish!
raise 'implement publish! on the inheriting class'
end
traceroute to digitalocean.com (141.101.115.8), 64 hops max, 52 byte packets
1 l100.nycmny-vfttp-226.verizon-gni.net (173.56.121.1) 4.101 ms 4.699 ms 2.971 ms
2 g1-1-3-3.nycmny-lcr-22.verizon-gni.net (130.81.180.4) 10.167 ms 11.152 ms 11.700 ms
3 ae4-0.ny5030-bb-rtr1.verizon-gni.net (130.81.163.224) 30.231 ms *
ae0-0.ny5030-bb-rtr1.verizon-gni.net (130.81.209.118) 39.039 ms
4 * 0.xe-3-2-0.il2.nyc9.alter.net (152.63.26.93) 7.402 ms
3.et-2-0-1.tl2.nyc1.alter.net (140.222.227.34) 7.501 ms
5 2.ae1.xt1.nyc4.alter.net (140.222.228.119) 31.797 ms
0.ae2.xl4.ewr6.alter.net (140.222.228.45) 49.313 ms
2.ae0.xt2.nyc4.alter.net (140.222.227.27) 96.378 ms
# http://www.programcreek.com/2013/12/leetcode-solution-of-longest-palindromic-substring-java/
require 'rspec'
def dynamic_lps(str)
return nil unless str.is_a?(String)
return str if str.length <= 1
longest_palindrome = ''
memo = Array.new(str.length) { Array.new(str.length) }
#!/usr/bin/env ruby
require 'set'
class Node
attr_accessor :email, :neighbors
def initialize(email)
@email = email
@neighbors = Set.new
end
#==============================================================================
# Resources
#==============================================================================
#
# Math and Logic - http://www.tutorialspoint.com/ruby/ruby_operators.htm
#
# Flow control:
# if/else - http://www.codecademy.com/glossary/ruby/if-unless-elsif-and-else
# looping - http://ruby.bastardsbook.com/chapters/loops/
#
#!/bin/sh
/sbin/iptables-restore < /etc/iptables.firewall.rules
*filter
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT
# Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow all outbound traffic - you can modify this to only allow certain traffic