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
@jgnagy
jgnagy / gist:5482519
Created April 29, 2013 15:51
DB2 stopping, round II
stop() {
echo -n $"Stopping $prog: "
dprofile || failure
db2gcf -s 1>>${DB2LOG} 2>&1
RETVAL=$?
if [ $RETVAL -gt 0 ]; then
echo -n $"${prog} is already stopped"
failure
RETVAL=3
echo ""
@jgnagy
jgnagy / gist:5482512
Created April 29, 2013 15:50
DB2 stopping...
stop() {
LOGFILE=$(mktemp)
echo -n $"Stopping IBM DB2 [${DB2USER}]"
# Is DB2 already stopped?
status
if [ $RETVAL -ne 0 ]; then
# Already stopped return 0
success
#!/usr/bin/env ruby
require './lib/framework/installer.rb'
include InstallerFramework
class TestInstaller < BaseInstaller
before { puts "Before hook 1" }
before { puts "Before hook 2" }