Skip to content

Instantly share code, notes, and snippets.

@vierarb
vierarb / .rubocop.yml
Created March 20, 2018 13:44
Proposed rubocop configuration for dmates
inherit_from:
- .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.3
Include:
- '**/Gemfile'
- '**/Rakefile'
- '**/config.ru'
Exclude:
@vierarb
vierarb / tictactoe.rb
Last active May 27, 2020 08:09
[TicTacToe] The game
class TicTacToe
def initialize
@player1 = Player.new(1, 'X')
@player2 = Player.new(2, 'O')
@players = [@player1, @player2]
@winner = false
@board = Board.new
end
def play
@vierarb
vierarb / text_to_json
Created May 26, 2020 15:44
Postgres: convert text to array of JSONs by regular expression
CREATE OR REPLACE FUNCTION text_to_json(text text, regex varchar) RETURNS json[] AS $$
DECLARE
chunk text;
res json[];
BEGIN
FOREACH chunk IN array regexp_split_to_array(text, regex)
LOOP
IF TRIM(chunk) <> '' THEN
BEGIN
res := res || chunk::json;