Skip to content

Instantly share code, notes, and snippets.

View as181920's full-sized avatar

andersen_fan as181920

  • vcooline
  • shanghai
View GitHub Profile
class PolicyTest < ActiveSupport::TestCase
def assert_permissions(current_user, record, available_actions, permissions_hash = {})
permissions_hash.each do |action, should_be_permitted|
if should_be_permitted
assert_permit current_user, record, action
else
refute_permit current_user, record, action
end
end
@as181920
as181920 / pg_pub_sub.rb
Created May 24, 2017 07:44 — forked from chsh/pg_pub_sub.rb
PostgreSQL LISTEN/NOTIFY example for ruby
#
# A:
# pubsub = PgPubSub.new('channelname')
# pubsub.subscribe do |data|
# puts "data: #{data} is coming!"
# end
#
# B:
# pubsub = PgPubSub.new('channelname')
# pubsub.publish("hello world")
### Keybase proof
I hereby claim:
* I am as181920 on github.
* I am as181920 (https://keybase.io/as181920) on keybase.
* I have a public key ASDbdqRnMVMIsViFMyPTTbravR8ZdwwHdLZyEyBiI0uK5go
To claim this, I am signing this object:
@as181920
as181920 / encryption-decryption.rb
Created April 20, 2018 05:24 — forked from gevans/encryption-decryption.rb
A couple examples of using asymmetric RSA signing and encryption using Ruby's OpenSSL libraries.
require 'openssl'
key = OpenSSL::PKey::RSA.new(2048)
p encrypted_string = key.public_encrypt('my plaintext string', OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
p decrypted_string = key.private_decrypt(encrypted_string, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
ec.order = ec.order || {};
ec.order.extraFields = ec.order.extraFields || {};
// A text input that asks a buyer how to sign the package
ec.order.extraFields.wrapping_box_signature = {
'title': 'How should we sign the package?',
'textPlaceholder': 'Package sign',
'type': 'text',
'tip': 'We will put a label on a box so the recipient knows who it is from',
'required': false,