Skip to content

Instantly share code, notes, and snippets.

View stevegrossi's full-sized avatar
😅
Lucky to be here

Steve Grossi stevegrossi

😅
Lucky to be here
View GitHub Profile
@stevegrossi
stevegrossi / image.rb
Created December 21, 2013 14:43
How to rename a Paperclip attachment when an interpolated attribute in the Filename changes
class Image < ActiveRecord::Base
attr_accessible :custom_file_name
has_attached_file :attachment
after_save :rename_attached_file, if: :rename_necessary?
def rename_attached_file
(attachment.styles.keys).each do |style|
@stevegrossi
stevegrossi / post-commit
Created January 10, 2014 20:03
When using git on a mac, this hook will speak your commit messages in a robot voice each time you commit. Just save this file within a git repository at .git/hooks/post-commit
#!/bin/bash
MESSAGE=$(git log -1 HEAD --pretty=format:%s)
say -v "Zarvox" "$MESSAGE"
@stevegrossi
stevegrossi / jmeter.rb
Last active March 19, 2018 16:16
Sample JMeter test plan using the ruby-jmeter gem
#!/usr/bin/env ruby
require 'ruby-jmeter'
test do
defaults domain: 'beta.stevegrossi.com'
cookies clear_each_iteration: true
Name,Email,Role,Group: Test Group 1,Group: Test Group 2,Group: Test Group 3,Custom: Test Custom Field
Test User 1,testuser1@lesson.ly,learner,yes,yes,yes,oranges
Test User 2,testuser2@lesson.ly,learner,yes,yes,yes,oranges
Test User 3,testuser3@lesson.ly,learner,yes,yes,yes,oranges
Test User 4,testuser4@lesson.ly,learner,yes,yes,yes,oranges
Test User 5,testuser5@lesson.ly,learner,yes,yes,yes,oranges
Test User 6,testuser6@lesson.ly,learner,yes,yes,yes,oranges
Test User 7,testuser7@lesson.ly,learner,yes,yes,yes,oranges
Test User 8,testuser8@lesson.ly,learner,yes,yes,yes,oranges
Test User 9,testuser9@lesson.ly,learner,yes,yes,yes,oranges
@stevegrossi
stevegrossi / string_to_integer_bench.exs
Last active July 21, 2017 14:17
Elixir parsing stringy integers: rescue vs. regex
defmodule StringToIntegerBench do
use Benchfella
@word "string"
@integer "1234"
bench "regex for word" do
if numeric_string?(@word) do
@word |> String.to_integer
else
@stevegrossi
stevegrossi / command_parsing.ex
Created February 8, 2018 18:10
Elixir command parsing
# I've been wondering about a pattern-matching-driven approach to what we've been talking about, e.g.
def parse_command(input) do
input
|> String.strip
|> match_command
end
def match_command("north"), do: {Player, :move, [:north, player, world]}
def match_command("east"), do: {Player, :move, [:east, player, world]}
def test_code
puts "Yay!"
end