Skip to content

Instantly share code, notes, and snippets.

View mscoutermarsh's full-sized avatar

Mike Coutermarsh mscoutermarsh

View GitHub Profile
@mscoutermarsh
mscoutermarsh / rubocop.yml
Last active December 5, 2016 05:16
Rubocop setup - Group Project
AllCops:
Exclude:
- bin/**/*
- db/**/*
- vendor/**/*
Rails:
Enabled: true
# Disables "Use nested module/class definitions instead of compact style" warning
require 'base64'
require 'json'
require 'openssl'
json_params = { template: 'HelloWorld', message: 'Hello' }.to_json
encoded_params = Base64.urlsafe_encode64(json_params)
hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), 'your_secret_key', encoded_params)
hmac_digest = Base64.urlsafe_encode64([hmac].pack('H*'))
require 'imgkit'
require 'sinatra'
get '/hi' do
content_type 'image/jpg'
html = '<div style="font: Georgia,Cambria,\'Times New Roman\',Times,serif;">
<div style="width: 300px; padding: 5px;">
<img height="30" src="https://ph-avatars.imgix.net/114714/original?auto=format&amp;fit=crop&amp;crop=faces&amp;w=60&amp;h=60" style="border-radius: 50%;"width="30" data-reactid=".8.1.1.0.4.0.0.1.1.1.$166511.0.0.0.1"> <span style="font-weight: 600;">Fred Rivett</span><span style="color: #bbbbbb;"> - One half of @wecontrast</span>
<div style="padding: 5px;">
Hi <span style="background-color: #F6A98E;">People, this is highlighted here</span>'
@mscoutermarsh
mscoutermarsh / node.rb
Created November 7, 2015 20:32
MiniTest example
# A Node to be used within a LinkedList
class Node
attr_accessor :payload, :next_node
def initialize(payload, next_node = nil)
@payload = payload
@next_node = next_node
end
def to_s
class Pawn < Piece
def first_move?(y)
#Allowed to move 1 or 2 spaces.
if (color: :white && y_position: 1) || (color: :black && y_position: 6)
return true
if (y_position - y) < 3
else
return false
end
end
@mscoutermarsh
mscoutermarsh / freeze.rb
Created September 28, 2015 18:39
Freeze
# Run this in a console.
(0..100).map do |number|
x = "foo"
p x.object_id
end
# Then run this
(0..100).map do |number|
x = "foo".freeze
p x.object_id
# Old 😞
Post.preload(:user, :category, comments: { user: :avatar }).where(something: true).limit(100)
# New & Improved 😎
Post.with_preloads.where(something: true).limit(100)
scope :with_preloads, -> { preload preload_attributes }
class << self
def preload_attributes
[:user, :category, comments: { user: :avatar }]
end
end
Post.preload(:user, :category, comments: { user: :avatar }).where(something: true).limit(100)
@mscoutermarsh
mscoutermarsh / string.rb
Created March 26, 2015 01:06
string concat example
output = "1234\n" \
"5467\n" \
"more!"