Skip to content

Instantly share code, notes, and snippets.

:octocat:

Michael Coyne mjc-gh

:octocat:
Block or report user

Report or block mjc-gh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View visitors.csv
date visitor_id
2018-01-15 pFihzA
2018-01-15 6N2dMg
2018-01-15 P4rCVA
2018-01-15 RE3k5A
2018-01-15 sATrOg
2018-01-15 hz-j3A
2018-01-15 kVP6CQ
2018-01-15 upEtnw
2018-01-15 8uur7A
@mjc-gh
mjc-gh / deck.rb
Created Sep 27, 2018
Deck of Cards
View deck.rb
class Card < Struct.new(:rank, :suit)
def inspect
"#{rank} of #{suit}s"
end
end
##
# Problem #1 -- create a deck of cards and shuffle it
##
View smile-to-go.rb
require 'active_support/multibyte/chars'
require 'active_support/core_ext/string/inflections'
require 'json'
require 'httpi'
require 'nokogiri'
STG_CONTROL_FILE = '.last-date'.freeze
STG_CHANNEL_URL = 'https://hooks.slack.com/services/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'.freeze
STG_SKIPPED_MENUS = %w(Pastries Breakfast).freeze
View ssh-relay.md
ssh -L 3000:localhost:3000 -L 3001:localhost:3001 -L 3002:localhost:3002 -L 8000:localhost:8000 -L 35729:localhost:35729
View hkdf.rb
require 'openssl'
def hkdf(digest_klass, length, ikm, salt, info)
prk = OpenSSL::HMAC.digest(digest_klass.new, salt, ikm)
okm, t = '', ''
(length.to_f / digest_klass.new.length).ceil.times do |index|
t = OpenSSL::HMAC.digest(digest_klass.new, prk, "#{t}#{info}#{(index + 1).chr}")
okm << t
end
View message_verifier_test.rb
class MessageVerifierTest < ActiveSupport::TestCase
def test_null_serializer
verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", serializer: ActiveSupport::MessageEncryptor::NullSerializer)
message = verifier.generate("message", expires_in: 1.day, purpose: 'NullSerializer')
assert_equal "message", verifier.verify(message)
end
end
@mjc-gh
mjc-gh / benchmark.rb
Last active Jun 4, 2017 — forked from tonytonyjan/benchmark.rb
How fast is `reverse!` technique.
View benchmark.rb
# conversation: https://github.com/rack/rack/commit/734a00c5f4bb46e9a5e6e2677d89a2f285dcc185
#
# user system total real
# reverse: 0.030000 0.010000 0.040000 ( 0.046804)
# join: 0.090000 0.000000 0.090000 ( 0.092356)
# regexp: 0.080000 0.000000 0.080000 ( 0.087152)
# slice 0.010000 0.000000 0.010000 ( 0.004146)
require 'benchmark'
@mjc-gh
mjc-gh / Gemfile
Created Aug 18, 2016
Devise::Async::Stretch
View Gemfile
gem 'devise-async-stretch'
@mjc-gh
mjc-gh / application_controller.rb
Last active Aug 17, 2016
Simon Says Authorizer
View application_controller.rb
class ApplicationController < ActionController::Base
include SimonSays::Authorizer
self.default_authorization_scope = :current_user
end
@mjc-gh
mjc-gh / admin.rb
Last active Aug 17, 2016
Simon Says Roleable
View admin.rb
class Admin < ActiveRecord::Base
include SimonSays::Roleable
has_roles :design, :support, :moderator, as: :access
end
# > Admin.new.access
# => []
# > Admin.new(access: :support).access
You can’t perform that action at this time.