Skip to content

Instantly share code, notes, and snippets.

View ratbeard's full-sized avatar

Mike Frawley ratbeard

View GitHub Profile
require 'ipaddr'
module Rack
#
# BanHammer is a Rack middleware app that restricts access to your server
# using a black-list of IPv4/IPv6 addresses and ranges.
#
# MIT License - Hal Brodigan (postmodern.mod3 at gmail.com)
#
# Needlessly modified by Mike Frawley
a `module` is about == to a namespace
`@name` is an instance variable in a class
self == this
puts == console.printLn
initialize == constructor
`def method(*args)` takes an arbitrary number of arguments, and 'splats' them in to an array in the `args` variable. so we can call: `method(1,2,3,4,7775,5)
# http://roo.rubyforge.org/
# http://code.joejag.com/2009/using-ruby-to-parse-an-excel-document/
class Spreadsheet
def initialize(path, path_to_results='c:/tmp/resultz')
@path = path
@path_to_results =
end
def id
I've got some experimental stuff in unpublished branches / projects I use underscore in. Let me know if
you like any of these:
1.) Too many simple things take two lines to do in javascript, like:
_.reduce(list, {}, function (memo, value) {
memo[value] = true;
return memo;
});
// Function that builds both min and max functions since they use the same logic,
// the only thing difference being:
// - which Math function we use (min or max)
// - what the starting value is (Infinity or -Infinity)
// - what the comparison is (< or >) for the transform case.
// We can't curry this away without evaling or calling a function, so just pass in
// true if we want to use a greater than comparison, false to use less than.
//
// For the cases where no transform function is given we fast path out this trick:
// http://ejohn.org/blog/fast-javascript-maxmin/
/*!
* toggleAttr() jQuery plugin
* @link http://github.com/mathiasbynens/toggleAttr-jQuery-Plugin
* @description Used to toggle selected="selected", disabled="disabled", checked="checked" etc…
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
;(function($) {
$.fn.toggleAttr = function(attr) {
return this.each(function() {
$(this).attr(attr) ? $(this).removeAttr(attr) : $(this).attr(attr, attr);
@ratbeard
ratbeard / config.rb
Created May 23, 2011 20:19
Basic Implementation of Local Storage Adapter for Backup gem
# assuming running script from home dir, with local.rb inside the backup folder, load it:
require 'Backup/local'
Backup::Model.new(:my_backup, 'My Backup') do
archive :vim do |archive|
archive.add '/Users/mike.frawley/.vim'
end
store_with ::Backup::Storage::Local do |local|
@ratbeard
ratbeard / _article.html.erb
Created July 15, 2011 15:15
Middleman feature for generated pages based off entries in a data yaml file
<link rel="stylesheet" href="/stylesheets/news/detail.css" />
<section>
<div class="module central content">
<div class="post">
<h2><%= article.title %></h2>
<%= article.content %>
</div>
</div>
</section>
@ratbeard
ratbeard / {} == danger
Last active December 14, 2015 22:49
{} syntax is more dangerous than no-;
I thought of a good analogy to 'no ;' are bad argument:
~~~
I can recall getting bitten by 'no ;' once, but LOTS of times I've
gotten the dangling ',' in object literal bug:
this.options = { a:1, b:2, }
Modern browsers allow it so you typically don't spot it late in the game when ie7
@ratbeard
ratbeard / gist:5163180
Last active December 14, 2015 23:08
screenshot tag for cucumber
After('@screenshot') do |scenario|
filename = scenario.name.parameterize + ".png"
filename = "FAILED-#{filename}" if scenario.failed?
path = File.join("doc", "screenshots", filename)
page.driver.save_screenshot(path)
end