Skip to content

Instantly share code, notes, and snippets.

View kddnewton's full-sized avatar
👶
Paternity leave

Kevin Newton kddnewton

👶
Paternity leave
View GitHub Profile
@kddnewton
kddnewton / annoy_scanners_server.rb
Last active August 15, 2024 03:36
Annoy scanners
# I really don't like getting routing error notifications when scanners try to
# find vulnerabilities in our application. As such, this extends our routing
# to actually give a response, but it's likely not what they were looking for.
# If they're not using a headless browser, the `alert` is going to kill their
# productivity. If they are, they just might enjoy the youtube video anyway.
class AnnoyScannersServer
SCANNER_PATHS = %w[
/a2billing/admin/Public/index.php
/a2billing/common/javascript/misc.js
/a2billing/customer/templates/default/css/popup.css
@kddnewton
kddnewton / select.rb
Created October 27, 2017 19:19
Better selects for ActiveRecord
class << ActiveRecord::Base
prepend Module.new {
class SelectChain < BasicObject
INVALID_ARGUMENTS =
'.select.not arguments must be a list of one or more symbols'.freeze
def initialize(scope)
@scope = scope
end
@kddnewton
kddnewton / status_codes.rake
Last active August 29, 2015 14:20
Rack status codes
namespace :doc do
desc "Print HTTP status codes with associated symbols"
task :status_codes do
Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |symbol, status_code|
puts "#{status_code} :#{symbol}"
end
end
end
# Output from `bin/rake doc:status_codes`
@kddnewton
kddnewton / sudoku.py
Last active August 29, 2015 14:06
Sudoku Solver
#!/usr/bin/python
#
# Takes first command line argument as path to an input file.
# Input file is expected to contain 81 numbers, with 0
# representing empty spaces, and 1-9 representing given numbers.
from sys import argv, stdout, exit
# tries different possibilities, backtracks if necessary
def backtracking(domains, assignments, constraints):