Skip to content

Instantly share code, notes, and snippets.

@beaugaines
beaugaines / sass_random_colors.scss
Created May 22, 2016 16:43
random colors in sass
@mixin random-color($selector) {
#{$selector}: unquote("rgba(#{random(256) - 1}, #{random(256)-1}, #{random(256 - 1)}, #{random(100)/100})");
}
$tags: (h1, h2, h3, h4, h5, p, li, a, strong, small, em);
@each $tag in $tags {
#{$tag} {
@include random-color('color');
}
@beaugaines
beaugaines / contact_data.tsv
Created May 18, 2016 15:27
tsv contact data
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
First Name Last Name Email Address Phone Number Company Name
Gerhard Kautzer [email protected] 1-207-643-1816 Hodkiewicz-Lynch
Myra Crona [email protected] (724)196-9470 x998 Champlin-Hahn
Josh Donnelly [email protected] 081-799-3139 x248 Casper Group
Verna Farrell [email protected] 731.101.6219 Rosenbaum-Hane
Lauriane Stracke [email protected] 1-033-511-1831 x471 Prohaska-Sporer
Kaya Luettgen [email protected] (511)745-9273 Wyman, Trantow and Hane
Steve Davis [email protected] 787.315.2611 x747 Kuhic-Lowe
Citlalli Pfeffer [email protected] 329-584-6962 x047 Gorczany and Sons
Litzy Turcotte [email protected] 1-084-641-4078 x4410 Hintz-Schmitt
@beaugaines
beaugaines / devise_to_haml.sh
Created November 11, 2015 02:50
convert devise views to haml
for f in app/views/devise/**/*.erb; do html2haml -e $f ${f%erb}haml && rm $f; done
@beaugaines
beaugaines / domain_modeling
Created October 28, 2015 16:29
homebrew_domain_modeling
User
has_many :recipes
- email
- name
- location
Recipe
belongs_to :user
has_many :recipe_fermentables
@beaugaines
beaugaines / init_vs_accessor.rb
Created October 8, 2015 05:24
Initialize vs attr_accessor
class Dog
def initialize(breed, color)
@breed, @color = breed, color
end
def describe_me
"I am a #{@breed} and I am #{@color}"
end
end
<h1><%= markdown_to_html @post.title %></h1>
<div class="row">
<div class="col-md-8">
<small>
<%= image_tag(@post.user.avatar.tiny.url) if @post.user.avatar? %>
submitted <%= time_ago_in_words(@post.created_at) %> ago by
<%= @post.user.name %>
module ReverseObject
def reverse
case self
when Integer
to_s.reverse.to_i
when Float
to_s.reverse.to_f
end
end
end
@beaugaines
beaugaines / cat.rb
Last active August 29, 2015 14:25 — forked from spraints/cat.rb
require 'benchmark'
puts "#{RUBY_ENGINE rescue ''} #{RUBY_ENGINE == 'jruby' ? JRUBY_VERSION : RUBY_VERSION}"
def a ; "abc"*100 ; end
def b ; "def"*100 ; end
n = 1000000
Benchmark.bm(12) do |x|
x.report('"#{a}#{b}"') { n.times { "#{a}#{b}" } }
x.report('"" + a + b') { n.times { "" + a + b } }
x.report('"" << a << b') { n.times { "" << a << b } }
end
class ChangeColumnTypeForUserRole < ActiveRecord::Migration
ROLES = User.roles.keys
def up
users = User.all
rename_column :users, :role, :old_role
add_column :users, :role, :integer, default: 0
users.all.each do |u|
u.update(role: ROLES.index(u.old_role))
@beaugaines
beaugaines / incoming_controller.rb
Created April 15, 2015 13:51
incoming_controller.rb
class IncomingController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:create]
def create
@user = User.find_by(email: params[:sender])
if @user.nil?
head 500
end