Skip to content

Instantly share code, notes, and snippets.

View cjavdev's full-sized avatar
👉

CJ Avilla cjavdev

👉
View GitHub Profile
@cjavdev
cjavdev / dump.rake
Created October 5, 2023 13:17
Handy little rake task for dumping prod db locally then redacting
namespace :dump do
task db: :environment do
if !Rails.env.development?
raise "This task is only available in development environment"
end
puts "Removing potential existing backups..."
if File.directory?("/tmp/backups")
FileUtils.rm_rf("/tmp/backups")
end
ActiveRecord::Base.connection.execute(<<-SQL)
UPDATE projects
SET comments_count = (
SELECT COUNT(*)
FROM comments
WHERE comments.commentable_id = projects.id
AND comments.commentable_type = 'Project'
)
SQL
// TODO: Make typescript happy here.
type JSONValue =
| string
| number
| boolean
| { [x: string]: JSONValue }
| Array<JSONValue>;
interface JSONObject {
[x: string]: JSONValue;
if ARGV.empty?
data = DATA.readlines(chomp: true)
else
data = File.readlines(ARGV[0], chomp: true)
end
solved = {}
expressions = {}
data.each do |line|
if ARGV.empty?
data = [1, 2, -3, 3, -2, 0, 4]
else
data = File
.readlines(ARGV[0], chomp: true)
.map(&:to_i)
end
def mix(data)
# iterate over all the elements and
if ARGV.empty?
data = DATA.readlines(chomp: true)
else
data = File.readlines(ARGV.first, chomp: true)
end
def blueprints(data)
data.map do |line|
match = /Blueprint (?<id>\d+): Each ore robot costs (?<ore_robot_ore>\d+) ore. Each clay robot costs (?<clay_robot_ore>\d+) ore. Each obsidian robot costs (?<obsidian_robot_ore>\d+) ore and (?<obsidian_robot_clay>\d+) clay. Each geode robot costs (?<geode_robot_ore>\d+) ore and (?<geode_robot_obsidian>\d+) obsidian./.match(line)
class Piece
attr_reader :shape, :kind
ORDER = [
:dash,
:plus,
:jay,
:line,
:square
if ARGV.empty?
data = DATA.readlines(chomp: true)
else
data = File.readlines(ARGV[0], chomp: true)
end
VALVES = {}
GRAPH = {}
@cjavdev
cjavdev / day16.rb
Last active December 17, 2022 22:18
# require 'set'
# require 'byebug'
if ARGV.empty?
data = DATA.readlines(chomp: true)
else
data = File.readlines(ARGV[0], chomp: true)
end
ADJ = {}