Skip to content

Instantly share code, notes, and snippets.

@jgnagy
jgnagy / wooden_puzzle.rb
Created March 15, 2022 04:54
A Puzzle Solution
class Cube
attr_accessor :sides
ALLOWED_COLORS = %i[red green yellow blue].sort.freeze
def initialize(sides)
@sides = sides
end
def rotate!
def log(message, level: :info)
message.split("\n").each { |line| logger(level, line) }
end
tenant.rb
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class Tenant
attr_reader :nickname, :occupation
attr_writer :nickname, :occupation
def initialize f_name, l_name, born_on, gender
@f_name = f_name
@l_name = l_name
@born_on = born_on
tab_count = 0
File.readlines('/path/to/file').each do |line|
# The regexp looks for 1 or more tabs at the beginning of the line as a group.
# We then split the result by character, then get the size of the Array from the split.
# Only do all that if the line matches the regexp in the first place.
tab_count += line.match(/^([\t]+)/)[1].split('').size if line.match /^([\t]+)/
end
@jgnagy
jgnagy / rabbitmq.json
Created June 21, 2016 16:10
example rabbitmq.json
{
"rabbitmq": {
"port": 5671,
"host": "sensu-rabbitmq-elb.domain.tld",
"user": "sensumq",
"password": "SomeSecretP4ssw0rd%",
"vhost": "/sensu",
"reconnect_on_error": true,
"prefetch": 1,
"ssl": {
@jgnagy
jgnagy / spf.rb
Last active June 15, 2016 22:21
A sloppy shortest-path-first example
#!/usr/bin/env ruby
class Connection
include Comparable
attr_reader :node
attr_accessor :metric
def initialize(node, metric)
@node = node
@metric = metric
set groups knuedge-default-applications applications application knu-ftp application-protocol ftp
set groups knuedge-default-applications applications application knu-ftp protocol tcp
set groups knuedge-default-applications applications application knu-ftp destination-port 21
set groups knuedge-default-applications applications application knu-tftp application-protocol tftp
set groups knuedge-default-applications applications application knu-tftp protocol udp
set groups knuedge-default-applications applications application knu-tftp destination-port 69
set groups knuedge-default-applications applications application knu-rtsp application-protocol rtsp
set groups knuedge-default-applications applications application knu-rtsp protocol tcp
set groups knuedge-default-applications applications application knu-rtsp destination-port 554
set groups knuedge-default-applications applications application knu-netbios-session protocol tcp
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS template for a dev AEM full stack (author, publish, mongoDB)",
"Parameters" : {
<%= snippet 'instance_typical_parameters', single_subnet: true %>,
<%= snippet 'aem_instance', section: 'parameters', type: 'author' %>,
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "AWS template for single mongoDB instance",
"Parameters" : {
<%= snippet 'instance_typical_parameters', single_subnet: true %>,
<%= snippet 'mongodb_instance', section: 'parameters' %>
@jgnagy
jgnagy / gist:f9a05b66958330597c18
Created June 3, 2015 16:39
999,999th number in Fibonacci sequence
1207194745159141002826404174456835022542798090334188844771315891233715000598678011112260318888075123689592411834936979490736524612541129464916133196891959089390781508801901190462549514293718039705568577408135381168081934297239755854973711511532698185611024500412162197188979941288282020199573223408206774596668313419963826711725161043107722443853859900192918402327537438078469032812456071967433560375713637786078248840381478654987462943199250096004040862399113422853029370751040053862717964433238100906729985033234799338852390831799253751350632777361017456834889870074002912701092879965450926881054241126908870540348960463175247436219452428209265049417169007299590697378642840148464590211385838000114628982182435757051247732335317975244558145013800143780053122458682872996807051063531696492049728550115119098138472631498417182798577064448005845249853541692837686154070672744221573088731124717769950442621024457847648217097034566477163229212995181070116278751184697983793032830380090615180747341198980152539452924807742625701