Skip to content

Instantly share code, notes, and snippets.

View woods's full-sized avatar

Scott Woods woods

View GitHub Profile
@woods
woods / geoip.sh
Last active February 10, 2025 12:58
iptables geoip xtables firewall by country
# This is an example of how to use xtables / xt_geoip to block requests
# based on their source/destination country.
#
# It can be computationally expensive to have tons of iptables rules.
# According to the bottom of the following page, this xt_geoip is probably
# about as efficient as can be for doing this kind of thing:
# http://xtables-addons.sourceforge.net/geoip.php
# Install packages
apt-get install xtables-addons-common libtext-csv-xs-perl unzip
@woods
woods / incrementer.rb
Created October 7, 2015 21:13
We don't need no stinkin' databases!
#!/usr/bin/env ruby
require 'yaml'
puts "How many sections?"
number_of_sections = Integer(gets)
data = YAML.load(DATA)
data['start'] = data['end'] + 1
data['end'] += number_of_sections
@woods
woods / lightning.html
Last active September 22, 2015 15:24
wufoo embed code for hacky hour lightning talk form
<div id="wufoo-p1nx3plw0skd0cb">
Fill out my <a href="https://westarete.wufoo.com/forms/p1nx3plw0skd0cb">online form</a>.
</div>
<script type="text/javascript">var p1nx3plw0skd0cb;(function(d, t) {
var s = d.createElement(t), options = {
'userName':'westarete',
'formHash':'p1nx3plw0skd0cb',
'autoResize':true,
'height':'620',
'async':true,
$ echo 'puts "hi"' > hello.rb
$ irb
irb(main):001:0> require 'hello'
LoadError: cannot load such file -- hello
from /Users/woods/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/woods/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
from /Users/woods/.rbenv/versions/2.2.2/bin/irb:11:in `<main>'
@woods
woods / console.txt
Created August 14, 2015 02:28
load vs require
~/westarete/src/flip-learning | 30248d7 | master
[532] $ echo 'puts "hi"' > hello.rb
~/westarete/src/flip-learning | 30248d7 | master*
[533] $ irb
irb(main):001:0> require 'hello'
LoadError: cannot load such file -- hello
from /Users/woods/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/woods/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from (irb):1
class User
has_many :things
has_many :sub_things, through: :things
has_many :sub_sub_things, through: :sub_things
end
@woods
woods / current_partner.rb
Created May 13, 2015 20:19
How we might spec out the global current_partner method
# This lives in config/initializers/current_partner.rb
# A global method to return the current partner
def current_partner
Partner.current
end
irb(main):006:0* class Dog
irb(main):007:1> def bark
irb(main):008:2> puts "Ruff!!"
irb(main):009:2> end
irb(main):010:1> def age
irb(main):011:2> 12
irb(main):012:2> end
irb(main):013:1> end
=> :age
irb(main):014:0>
@woods
woods / application_helper.rb
Created January 8, 2015 14:40
An example of a helper for determining which instance/flavor we're running.
# A helper for determining which partner site we're on. This can be
# used for setting a CSS class on the body tag in the layout, or
# for referencing namespaced assets or translations.
def parner(host=request.host)
if $ENV['PARTNER'] == 'graduate' || host =~ /graduate/i
'graduate'
elsif $ENV['PARTNER'] == 'schreyer' || host =~ /schreyer/i
'schreyer'
else
# decide whether to fail or default to one of the above
# Include this module into your fake models to get some helpful default functionality.
#
# Example usage:
#
# class AuxiliaryOfficer
# include FakeModel
#
# attr_accessor :name, :started_on, :comments
#
# def self.fake_attributes