Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / .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 / Dockerfile
Created August 14, 2017 07:56
Docker configuration
FROM ruby:2.4.1
RUN apt-get update -qq && apt-get install -y build-essential
# for postgres
RUN apt-get install -y libpq-dev
# for nokogiri
RUN apt-get install -y libxml2-dev libxslt1-dev
@vierarb
vierarb / Dvorak_ES.keylayout
Last active August 29, 2015 14:10
Dvorak keylayout with custom spanish disposition
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!-- Fri, 24 Feb 2006 Generated from KCHR: "Dvorak" -->
<!-- Author: Laura Paredes <laura@wearepeople.io>-->
<!--Last edited by Ukelele version 2.2.8 on 2014-12-21 at 09:58 (CET)-->
<keyboard group="0" id="16300" name="Dvorak ES" maxout="1">
<layouts>
<layout first="0" last="0" modifiers="commonModifiers" mapSet="ANSI"/>
</layouts>
<modifierMap id="commonModifiers" defaultIndex="0">
@vierarb
vierarb / Guardfile
Created November 29, 2014 18:03
Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
@vierarb
vierarb / .rubocop-todo.yml
Last active August 29, 2015 14:08
Rubocop config file proposal
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-02-23 19:26:33 +0100 using RuboCop version 0.29.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
Lint/Void:
Enabled: false
@vierarb
vierarb / foursquare_place.rb
Last active August 29, 2015 14:04
Foursquare Places
class FoursquarePlace
include Cacheable
ATTRIBUTES = %i(pid name street city country latitude longitude icon
categories)
def initialize(attrs = {})
@connection = FoursquareConnector.new
_initialize_attributes!(attrs)
@vierarb
vierarb / redis.rb
Last active August 29, 2015 14:03
Redis Storage
$redis = Redis.new(host: 'localhost', port: 6379, db: 1)
@vierarb
vierarb / gist:9b1986a78d14f5dae60d
Created May 23, 2014 15:58
Polar Area chart with d3js
var width = 750;
var height = 500;
var radius = 200;
var strokeColor = "#999";
var strokeOpacity = 0.75;
var labelMargin = radius + 20;
var concentric = [];
for(var i = 1; i <= 10; i++) {
concentric.push((radius * i) / 10);