Skip to content

Instantly share code, notes, and snippets.

View mattantonelli's full-sized avatar

Matt Antonelli mattantonelli

  • 02:58 (UTC -04:00)
View GitHub Profile
@mattantonelli
mattantonelli / qbs
Created October 29, 2014 15:56
Odds of picking QBs on two different teams that share the same bye week.
32 NFL teams
9 bye weeks, differing teams
Odds that both QBs (assume different teams) are bye on same week?
Team combinations: 992
Bye weeks:
Week 4
Arizona Cardinals, Cincinnati Bengals, Cleveland Browns, Denver Broncos, St. Louis Rams, Seattle Seahawks
@mattantonelli
mattantonelli / poke.json
Last active August 29, 2015 14:11
1st Generation Pokemon
[ { "id": "1", "name": "Bulbasaur" }, { "id": "2", "name": "Ivysaur" }, { "id": "3", "name": "Venusaur" }, { "id": "4", "name": "Charmander" }, { "id": "5", "name": "Charmeleon" }, { "id": "6", "name": "Charizard" }, { "id": "7", "name": "Squirtle" }, { "id": "8", "name": "Wartortle" }, { "id": "9", "name": "Blastoise" }, { "id": "10", "name": "Caterpie" }, { "id": "11", "name": "Metapod" }, { "id": "12", "name": "Butterfree" }, { "id": "13", "name": "Weedle" }, { "id": "14", "name": "Kakuna" }, { "id": "15", "name": "Beedrill" }, { "id": "16", "name": "Pidgey" }, { "id": "17", "name": "Pidgeotto" }, { "id": "18", "name": "Pidgeot" }, { "id": "19", "name": "Rattata" }, { "id": "20", "name": "Raticate" }, { "id": "21", "name": "Spearow" }, { "id": "22", "name": "Fearow" }, { "id": "23", "name": "Ekans" }, { "id": "24", "name": "Arbok" }, { "id": "25", "name": "Pikachu" }, { "id": "26", "name": "Raichu" }, { "id": "27", "name": "Sandshrew" }, { "id": "28", "name": "Sandslash" }, { "id": "29", "name": "Nidoran"
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
@mattantonelli
mattantonelli / .latest.migration.zshrc
Last active August 29, 2015 14:13
Open the latest migration for a Rails application in VIM
# Add to your .zshrc
# find git home directory
function find-git-home() {
git rev-parse --show-toplevel
}
# find the filename of the last migration based on file timestamp
function last-migration() {
ls -rt `find "$(find-git-home)/db/migrate" -type f -name "*" -print` | tail -1
@mattantonelli
mattantonelli / longest_joke
Last active March 8, 2018 18:01
Longest Joke
So, there's a man crawling through the desert.
He'd decided to try his SUV in a little bit of cross-country travel, had great fun zooming over the badlands and through the sand, got lost, hit a big rock, and then he couldn't get it started again. There were no cell phone towers anywhere near, so his cell phone was useless. He had no family, his parents had died a few years before in an auto accident, and his few friends had no idea he was out here.
He stayed with the car for a day or so, but his one bottle of water ran out and he was getting thirsty. He thought maybe he knew the direction back, now that he'd paid attention to the sun and thought he'd figured out which way was north, so he decided to start walking. He figured he only had to go about 30 miles or so and he'd be back to the small town he'd gotten gas in last.
He thinks about walking at night to avoid the heat and sun, but based upon how dark it actually was the night before, and given that he has no flashlight, he's afraid that he'll break a leg
# Check a valid date string to match the format 'YYYY-MM-DD'
def valid_date?(date)
Date.valid_date?(*date.split('-').map(&:to_i))
end
# Validate fields in different ActiveRecord objects with the same
# validation class without having to share the same field name.
#
# Field name is provided in the controller as follows:
# validates_with MyValidator, field: :field_name
#
def validate(record)
field = options[:field]
if !(valid_field?(record[field]))
record.errors.add(field, "invalid_#{field}".to_sym)
@mattantonelli
mattantonelli / iptables_open_port.sh
Last active August 29, 2015 14:17
Open a port in CentOS
# Open port 3001, which will accept communication on localhost:3001
sudo iptables -I INPUT -p tcp --dport 3001 -j ACCEPT
sudo service iptables save
# Detailed How-To for iptables can be found at: http://wiki.centos.org/HowTos/Network/IPTables
@mattantonelli
mattantonelli / cascading_selects_rails.md
Last active August 29, 2015 14:18
Adding Cascading Selects to Rails Forms

Adding Cascading Selects to Rails Forms

Edit: I have created a gem that makes it simple to set up cascading selects in Rails. Check it out here!

The following guide details how to get up and running with cascading selects to forms in Rails using jquery-dynamic-select.

Cascading selects allows you to select an option in one select field, and have it dynamically populate another field on the form based on your selection. For example, if you had a form for entering car information, the field Make would determine the values to be shown in Model. (e.g. Nissan → Altima, Maxima, etc.) Using this jQuery library will allow you to populate the second select field without having to reload the page.

The example implementation will implement a cascading select for a Terminal form. A Terminal belongs to a Serving Area, which itself belongs to an Exchange. In order to properly create a Terminal, we must

@mattantonelli
mattantonelli / astar.rb
Last active August 29, 2015 14:18
Quick implementation of A* in Ruby
#!/usr/bin/env ruby
# encoding: utf-8
class AStar
def initialize(width, height, max_cost)
@grid = create_random(width, height, max_cost)
@start = @grid[0][0]
@end = @grid[height - 1][width - 1]
@open, @closed = [], [@start]
end