Skip to content

Instantly share code, notes, and snippets.

@dogweather
dogweather / gist:2234066
Created March 29, 2012 06:15
Deny all traffic from an IP address
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 October 23, 2012 00:02
My IPN model.
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 October 23, 2012 02:03
Trying to use pry to learn about a gem/module
[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 November 2, 2012 03:10
Making Heroku deploy a one-liner
# 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 January 25, 2013 23:03
Sync an svn repo to git. A simple script that can be run from a cron job.
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
=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 December 29, 2015 13:59
Read a file into a string.
contents = File.open('file.txt') { |f| f.read }
@dogweather
dogweather / slurp-text-file.py
Last active December 29, 2015 14:29
Read a text file into a string and close the file.
with open('file.txt') as f: contents = f.read()
@dogweather
dogweather / for-loop.rb
Last active December 30, 2015 20:49
Iterate through an array, printing each element on a separate line.
an_array.each { |item| puts item }
# or
an_array.each do |item|
puts item
end
# or
@dogweather
dogweather / variable-length-argument-list.rb
Created December 10, 2013 23:00
Define a method with a variable length argument list
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