Skip to content

Instantly share code, notes, and snippets.

View patmaddox's full-sized avatar
🤔
Trying to figure out how to look up comments I've left

Pat Maddox patmaddox

🤔
Trying to figure out how to look up comments I've left
View GitHub Profile
something = case option_type
when OptionType then "do this"
when String then "do this thing"
else "how about this"
end
something = if option_type.class == OptionType
"do this"
elsif option_type.class == String
"do this thing"
[1] pry(main)> hash = {a: 1, b: 2, c: 3}
=> {:a=>1, :b=>2, :c=>3}
[2] pry(main)> class Hash
[2] pry(main)* def retrieve_keys(*keys)
[2] pry(main)* self.reduce({}) { |h, (k, v)|
[2] pry(main)* keys.include?(k) ? h.merge!({k => v}) : h
[2] pry(main)* }
[2] pry(main)* end
[2] pry(main)* end
=> nil
@patmaddox
patmaddox / gist:9100174
Created February 19, 2014 19:50
how to stop twitter from spamming your iPhone
Hi, your instructions kind of suck but I figured it out. Here's how to actually do it:
From the iOS app...
1) Go to the Me tab, tap the gear icon, then click settings
2) Tap on the account name to open the notifications settings for that account (critical missing piece of info)
3) Disable "Recommendations" "news" and "other"
Pat
@patmaddox
patmaddox / environments_production.rb
Last active August 29, 2015 13:57
<srbaker>SOLVED</srbaker>
default_attributes chef_user: "ubuntu"
default_attributes { ... a whole mess of other stuff which apparently blows away the first line. whoops }
pat-jukely:active_rest_client pat$ pwd
/Users/pat/code/opensource/active_rest_client
pat-jukely:active_rest_client pat$ bundle install
OH HAI! I am /Users/pat/code/opensource/active_rest_client/Gemfile
OH HAI! I am /Users/pat/code/opensource/active_rest_client/Gemfile
Resolving dependencies...
...
Your bundle is complete!
It was installed into ./vendor/bundle
OH HAI! I am /Users/pat/code/opensource/active_rest_client/Gemfile
@patmaddox
patmaddox / exercise_2c_objects_spec.rb
Created August 7, 2014 02:10
rubysteps 008 - tdd - approval tests snippet
require 'approvals/rspec'
def output_methods(target, methods)
methods.inject([]) do |results, m|
results << %("#{target}".#{m} => #{target.send(m)})
end
end
describe "Ruby standard library" do
it "has a useful String class" do
@patmaddox
patmaddox / rubysteps.rb
Created August 8, 2014 01:54
RubySteps 009 - OOP - Easty OOP (excerpt)
class StarWrapper
def initialize(stream)
@stream = stream
end
def puts(string)
print_header_line string
@stream.print "* "
@stream.print string
@stream.puts " *"
@patmaddox
patmaddox / exercise_1a_legacy_1_spec.rb
Created August 9, 2014 07:12
RubySteps Lesson 010 - Refactoring - Legacy Code - excerpt
require 'rspec'
class Order
def initialize(customer_name)
@customer_name = customer_name
@items = []
end
def purchase(name, quantity, price)
@items << {name: name, quantity: quantity, price: price}
@patmaddox
patmaddox / authorized_controller.rb
Created August 13, 2014 04:20
RubySteps 012 - Rails - Mini frameworks snippet
module AuthorizedController
# ... full code in the paid lesson
def show
resource = resource_by_id
if resource.viewable_by?(current_user)
render json: resource
else
render text: 'Unauthorized', status: :unauthorized
@patmaddox
patmaddox / gist:f22617685ccce1053951
Last active August 29, 2015 14:07
question about gemfury
Hi, I haven't used Gemfury at all (yet) and I've only briefly clicked around...
I hope you don't mind answering some questions that might be covered elsewhere that
I just haven't found yet.
I want to distribute code to RubySteps members. I've been using git, which is obviously awesome,
but it doesn't really let me limit who gets what and when. I thought that was an advantage at
first, but it turns out that people get overwhelmed when I just throw the whole thing at them.
I could create a separate git repository for each member and push their new code there...