Skip to content

Instantly share code, notes, and snippets.

View mjc-gh's full-sized avatar
🎯
Open Sourcing

Michael Coyne mjc-gh

🎯
Open Sourcing
View GitHub Profile
@mjc-gh
mjc-gh / benchmark.rb
Last active June 4, 2017 06:49 — forked from tonytonyjan/benchmark.rb
How fast is `reverse!` technique.
# 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 August 18, 2016 16:27
Devise::Async::Stretch
gem 'devise-async-stretch'
@mjc-gh
mjc-gh / application_controller.rb
Last active August 17, 2016 17:41
Simon Says Authorizer
class ApplicationController < ActionController::Base
include SimonSays::Authorizer
self.default_authorization_scope = :current_user
end
@mjc-gh
mjc-gh / admin.rb
Last active August 17, 2016 17:37
Simon Says Roleable
class Admin < ActiveRecord::Base
include SimonSays::Roleable
has_roles :design, :support, :moderator, as: :access
end
# > Admin.new.access
# => []
# > Admin.new(access: :support).access
@mjc-gh
mjc-gh / reporters_controller.rb
Created August 17, 2016 17:09
Simon Says Example
class ReportsController < ApplicationController
authorize_resource :admin, :support
find_resource :report, from: :current_admin, except: [:index, :new, :create]
end
@mjc-gh
mjc-gh / example_1.js
Last active June 1, 2016 14:11
JavaScript Code Examples
// Sample A
var x = y;
function y(){};
// Sample B
var a = b;
var b = function(){};
// Sample C
i = j;
# http://www.barkingiguana.com/2010/04/11/a-one-line-web-server-in-ruby/
ruby -rwebrick -e'WEBrick::HTTPServer.new(port: ARGV.pop.to_i, BindAddress: ARGV.pop.to_s, DocumentRoot: Dir.pwd).start'
@mjc-gh
mjc-gh / page_visibility.js
Created November 6, 2013 21:43
Page visibility jQuery API
(function($){
var prop = 'VisibilityState';
var evt = 'visibilitychange';
var vendors = ['webkit', 'ms'];
var vendor;
function set_state(state){
$(window).trigger('visibilitychange', state);
@mjc-gh
mjc-gh / event_source_factory.js
Created October 5, 2013 16:29
Simple EventSource factory object for angular.js
!function(factories){
factories.factory('$eventSource', ['$window', function($window){
var EventSource = $window.EventSource;
function parse(obj){
try { var json = JSON.parse(obj); }
catch(e) { json = {}; }
finally { return json; }
}
st# status bar
set-option -g status-utf8 on
# https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf
set-option -g status-bg colour235 #base02
set-option -g status-fg colour136 #yellow
set-option -g status-attr default
# default window title colors
set-window-option -g window-status-fg colour244 #base0