Skip to content

Instantly share code, notes, and snippets.

View jeremywrowe's full-sized avatar
❤️
Coding

Jeremy W. Rowe jeremywrowe

❤️
Coding
View GitHub Profile
@jeremywrowe
jeremywrowe / gist:4755a9558b594c231313
Last active August 29, 2015 14:19
config/environment.js
var fs = require('fs'),
path = './bower_components/fontawesome/scss/_icons.scss',
regex = /\.#{\$fa-css-prefix}([-|\w]+):before/g,
match,
data;
ENV.APP.awesomeness = [];
data = fs.readFileSync(path, 'utf8');
while(match = regex.exec(data)) {
RSpec.configure do |c|
if c.respond_to?(:default_color=)
c.failure_color = :green
c.success_color = :green
end
end
@jeremywrowe
jeremywrowe / grouping.rb
Created November 24, 2014 00:41
MySql Group Concat
Customer.joins(subscriptions: :product).group(:email).select('GROUP_CONCAT(DISTINCT subscriptions.state SEPARATOR ":::") AS states, GROUP_CONCAT(DISTINCT products.name SEPARATOR ":::") AS product_names, first_name, last_name').last.states
class Base
DEFAULT_PROC = -> () {}
def initialize(api_key, connection_class = External::Service, builder = -> (klass, key) { klass.new(key) })
@api_key = api_key
@builder = builder
@connection_class = connection_class
end
def execute(&block)
@jeremywrowe
jeremywrowe / clogs.zsh.sh
Created March 16, 2014 22:57
ZSH function to truncate Rails logs
function clogs() {
if [[ -d log ]]; then
echo 'cleaning logs'
: > log/*.log
else
echo 'logs dir not found'
fi
}
@jeremywrowe
jeremywrowe / class_level_privates.rb
Created February 22, 2014 01:33
I see the top implementation of class level private methods a lot. Please understand that the private means nothing in that case. Do you know why? :)
# The wrong way to make a class level method private
class Foo
def self.bar
p "bar"
end
private
def self.baz
@jeremywrowe
jeremywrowe / Rakefile
Created February 16, 2014 03:06
Jekyll Rake task for making a new post
desc 'creates a new post prefixed with the current date'
task :post, :name, :title, :categories do |task, args|
File.open(File.join('_posts', Time.now.strftime("%Y-%m-%d-#{args[:name].split(' ').join('-')}.markdown")), 'w') do |file|
file << <<-DOC
---
layout: post
title: "#{args[:title].downcase}"
date: #{Time.now.strftime("%Y-%m-%d-%H:%M:%S")}
categories: #{args[:categories].downcase}
---
require 'active_support/core_ext/string/inquiry.rb'
def speak_like_a(val)
is = val.inquiry
if is.chicken?
puts "bagaaawk"
elsif is.pig?
puts "oink"
else
puts "sorry don't know what tongue that speak in"
@jeremywrowe
jeremywrowe / refinement.rb
Last active January 2, 2016 09:29
Example of ruby 2.1 refinements and their glory. Use with caution -- They are kind of code stinkies.
module Refinement
refine String do
def reverse
self[0..1]
end
end
end
class Boom
@jeremywrowe
jeremywrowe / saving_private_ruby.rb
Created January 6, 2014 14:13
This is a display of taking advantage of ruby 2.1 returning a symbol representation of methods when created and passing it to private as a single argument.
class Test
# :( wish this worked
private def self.bar
puts "self bar"
end
# would be nice to not have to do this
class << self
private def nook
puts "self nook"