Skip to content

Instantly share code, notes, and snippets.

Avatar

Sean Handley seanhandley

View GitHub Profile
@seanhandley
seanhandley / binary_tree.rb
Last active Jul 27, 2016
A simple binary tree structure
View binary_tree.rb
module BinaryTree
class Node
attr_reader :element
attr_accessor :left, :right
def initialize(e=nil)
@element = e
end
def traverse
View clouds.yaml
clouds:
datacentred:
auth:
username: YOUR_USERNAME
password: YOUR_PASSWORD
project_name: YOUR_PROJECT_NAME
auth_url: https://compute.datacentred.io:5000/v2.0/
@seanhandley
seanhandley / verbose_db_output.rb
Created Jun 2, 2016
Get SQL debug info in production Rails console
View verbose_db_output.rb
Rails.configuration.log_level = :info
ActiveRecord::Base.logger = Logger.new(STDOUT)
# run your code
View my-nginx-server.conf
server {
listen 443 ssl http2;
server_name awesomehost.ninja;
ssl_certificate /path/to/server.crt;
ssl_certificate_key /path/to/server/key
ssl_client_certificate /path/to/client-ca.crt;
ssl_verify_client optional;
location /secret {
View application_controller.rb
class ApplicationController < ActionController::Base
def no_layout?
params.keys.include?('no_layout')
end
end
View client.erb
<%= link_to "Edit", @model.edit_path %>
View code.rb
I18n.t("model_helper_texts.#{model.downcase.underscore}.#{attribute_name.downcase.underscore})
@seanhandley
seanhandley / golfed.rb
Last active Nov 15, 2015
Einstein 17: Golfed to 546 characters
View golfed.rb
# With newlines, for readability
def q(a);
a.permutation;
end;
def n(a,b,c,d);
i(a,b,c,d,1)||i(c,d,a,b,1);
end;
def i(a,b,c,d,o=0);
(0..4).any?{|i|a[i]==b&&c[i+o]==d};
end;
@seanhandley
seanhandley / permutation.rb
Created Nov 15, 2015
Einstein 16: Permutation
View permutation.rb
def q(a)
a.permutation
end
q([1,2,3]).to_a # => [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
@seanhandley
seanhandley / merge.rb
Created Nov 15, 2015
Einstein 15: Merging left_of? with implies?
View merge.rb
# Implies
def i(a, b, c, d)
(0..4).any? do |i|
a[i] == b &&
c[i] == d
end
end
# Left of
def l(a, b, c, d)
You can’t perform that action at this time.