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
def test_code
puts "Yay!"
end
@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]}
@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
Name,Email,Role,Group: Test Group 1,Group: Test Group 2,Group: Test Group 3,Custom: Test Custom Field
Test User 1,[email protected],learner,yes,yes,yes,oranges
Test User 2,[email protected],learner,yes,yes,yes,oranges
Test User 3,[email protected],learner,yes,yes,yes,oranges
Test User 4,[email protected],learner,yes,yes,yes,oranges
Test User 5,[email protected],learner,yes,yes,yes,oranges
Test User 6,[email protected],learner,yes,yes,yes,oranges
Test User 7,[email protected],learner,yes,yes,yes,oranges
Test User 8,[email protected],learner,yes,yes,yes,oranges
Test User 9,[email protected],learner,yes,yes,yes,oranges
@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
@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 / 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|