This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'ripper' | |
# A Ripper parser that will replace usage of Sorbet patterns with whitespace so | |
# that location information is maintained but Sorbet methods aren't called. | |
class Eraser < Ripper | |
# Represents a line in the source. If this class is being used, it means that | |
# every character in the string is 1 byte in length, so we can just return the | |
# start of the line + the index. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_constant_refs(iseq) | |
cached = false | |
iseq.last.each_with_object([]) do |insn, counts| | |
case insn | |
in [:opt_getinlinecache, *] | |
cached = true | |
counts << 0 | |
in [:getconstant, *] | |
counts[counts.length - 1] += 1 if cached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = [] | |
letters = ("a".."z").to_a | |
File.foreach("/usr/share/dict/words", chomp: true) do |word| | |
words << word.downcase if word.match?(/\A[a-z]{5}\z/i) | |
end | |
while words.length > 1 | |
weights = letters.to_h { |letter| [letter, 0] } | |
words.each do |word| |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module ActiveRecord | |
class Migration | |
class MigrationError < StandardError | |
end | |
RenameColumn = Struct.new(:table_name, :column_name, :new_column_name, keyword_init: true) | |
RemoveColumn = Struct.new(:table_name, :column_name, keyword_init: true) | |
AddColumn = Struct.new(:table_name, :column_name, :type, :options, keyword_init: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This is the opcode of the instruction. | |
enum Op { | |
Add, | |
Sub, | |
Mov, | |
} | |
/// This is a reference to a register. It is passed around when generating the | |
/// IR through the Assembler struct. When it gets loaded into an Insn struct as | |
/// part of a generated instruction, it is wrapped into an Opnd::Reg. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer