Skip to content

Instantly share code, notes, and snippets.

View paulsonkoly's full-sized avatar

Paul Sonkoly paulsonkoly

View GitHub Profile
<style type="text/css"> body { margin: 1em; width: 80%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; } kbd { display: inline-block; margin: 0 .1em; padding: .1em .6em;
require 'set'
require 'forwardable'
# Board is a 9x9 standard sudoku board. This class does not care about what is
# stored in each cell of the board, it merely provides indexing and enumeration
# methods including accessing rows, columns, or 3x3 sudoku boxes.
class Board
extend Forwardable
# @param data [Array] flat array of 81 initial cell values
require 'active_support/inflector'
# Argument parsing
# My solution to http://codingdojo.org/kata/Args/
module Args
# Error occured during argument parsing. {StandardError#message} should give
# a description about the error.
class ArgsError < StandardError; end
# An argument schema.
require 'set'
require 'forwardable'
# Board is a 9x9 standard sudoku board. This class does not care about what is
# stored in each cell of the board, it merely provides indexing and enumeration
# methods including accessing rows, columns, or 3x3 sudoku boxes.
class Board
extend Forwardable
# @param data [Array] flat array of 81 initial cell values
@paulsonkoly
paulsonkoly / sudoku.rb
Last active April 13, 2020 07:25
optimized
require 'forwardable'
# Board is a 9x9 standard sudoku board. This class does not care about what is
# stored in each cell of the board, it merely provides indexing and enumeration
# methods including accessing rows, columns, or 3x3 sudoku boxes.
class Board
extend Forwardable
# @param data [Array] flat array of 81 initial cell values
def initialize(data)
@paulsonkoly
paulsonkoly / y.rb
Last active December 11, 2019 10:47
validator
require 'active_support'
require 'active_model'
class Form
include ActiveModel::Validations
include ActiveModel::Attributes
attribute :blah
validates :blah, numericality: true
end
@paulsonkoly
paulsonkoly / x.rb
Created January 22, 2020 16:59
validators
require 'active_support'
require 'active_model'
class X
include ActiveModel::Validations
include ActiveModel::Attributes
attribute :blah
validates :blah, numericality: { greater_than_or_equal_to: 0 }
@paulsonkoly
paulsonkoly / x.rb
Created January 27, 2020 17:42
private stub
require 'rspec/autorun'
class X
def call
fund_query
end
private
def fund_qeuery
@paulsonkoly
paulsonkoly / y.rb
Created March 16, 2020 20:56
rspec
require 'rspec/autorun'
RSpec::Matchers.define :be_one_of do |expected|
match do |actual|
expected.include? actual
end
end
RSpec.describe 13 do
it 'is in the list of allowed values' do
@paulsonkoly
paulsonkoly / x.rb
Last active June 16, 2020 15:41
sandstorm
require 'tempfile'
module Music
refine Float do
def hz
self
end
def khz
self * 1000