Skip to content

Instantly share code, notes, and snippets.

Avatar

Robb Shecter dogweather

View GitHub Profile
@dogweather
dogweather / gist:2234066
Created Mar 29, 2012
Deny all traffic from an IP address
View gist:2234066
To insert the new rule before others (i.e. allow's) in the list:
ufw insert 1 deny from a.b.c.d
To check the placement:
ufw status numbered
@dogweather
dogweather / ipn.rb
Created Oct 23, 2012
My IPN model.
View ipn.rb
class Ipn < ActiveRecord::Base
belongs_to :user
serialize :message_data, Hash
#
# Return true if this is a payment.
#
def payment?
return paypal_subscription_payment? || weblaws_payment?
end
@dogweather
dogweather / gist:3936252
Created Oct 23, 2012
Trying to use pry to learn about a gem/module
View gist:3936252
[7] pry(main)> include Magick
=> Object
[8] pry(main)> ls
self.methods: include private public to_s
locals: _ _dir_ _ex_ _file_ _in_ _out_ _pry_
[9] pry(main)> ls -g
global variables: $! $" $$ $& $' $* $+ $, $-0 $-a $-d $-F $-i $-I $-K $-l $-p $-v $-W $-w $. $/ $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $: $; $< $= $> $? $@ $\ $_ $` $CODERAY_DEBUG $DEBUG $DEBUG_BEFORE $FILENAME $fileutils_rb_have_lchmod $fileutils_rb_have_lchown $KCODE $LOAD_PATH $LOADED_FEATURES $PROGRAM_NAME $SAFE $stderr $stdin $stdout $VERBOSE $~
[10] pry(main)> Image
=> Magick::Image
[11] pry(main)>
@dogweather
dogweather / .sh
Created Nov 2, 2012
Making Heroku deploy a one-liner
View .sh
# Heroku Convenience Aliases
alias precompile='rake assets:precompile; git add -f public/assets/manifest.yml; git commit -m manifest'
alias migrate='heroku run rake db:migrate'
alias clear_cache='heroku run rake cache:clear'
alias deploy='precompile; git push heroku master; migrate; clear_cache'
@dogweather
dogweather / svn-to-git.rb
Created Jan 25, 2013
Sync an svn repo to git. A simple script that can be run from a cron job.
View svn-to-git.rb
require 'Time'
require 'Nokogiri'
#
# svn-to-git
#
# Sync an svn repo to git.
#
# Checks for svn updates. If there are none, does
# nothing. Otherwise, commits & pushes the latest
View capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@dogweather
dogweather / slurp-text-file.rb
Last active Dec 29, 2015
Read a file into a string.
View slurp-text-file.rb
contents = File.open('file.txt') { |f| f.read }
@dogweather
dogweather / slurp-text-file.py
Last active Dec 29, 2015
Read a text file into a string and close the file.
View slurp-text-file.py
with open('file.txt') as f: contents = f.read()
@dogweather
dogweather / for-loop.rb
Last active Dec 30, 2015
Iterate through an array, printing each element on a separate line.
View for-loop.rb
an_array.each { |item| puts item }
# or
an_array.each do |item|
puts item
end
# or
@dogweather
dogweather / variable-length-argument-list.rb
Created Dec 10, 2013
Define a method with a variable length argument list
View variable-length-argument-list.rb
func(1, 2, 3, 4, 5)
# The argument with the "splat operator" denotes
# a variable number of arguments which will be
# placed into an array.
def func(arg1, arg2, *other_args)
p arg1.inspect # => 1
p arg2.inspect # => 2
p other_args.inspect # => [3, 4, 5]
end
You can’t perform that action at this time.