Skip to content

Instantly share code, notes, and snippets.

View ktopolski's full-sized avatar

Karol Topolski ktopolski

  • https://www.globalapptesting.com/
  • Krakow
  • X @_ktopolski
View GitHub Profile
@ktopolski
ktopolski / simplecov_merge.rb
Last active June 27, 2019 12:41
merge simplecov results
require 'json'
require 'simplecov'
Dir["coverage/.resultset-*.json"]
.map(&File.method(:read))
.map(&JSON.method(:parse))
.map { |json| SimpleCov::Result.new(json['RSpec']['coverage']) }
.then { |results| SimpleCov::ResultMerger.merge_results(*results) }
.then { |merged_result| merged_result.covered_percent < 100 }
@ktopolski
ktopolski / index.html
Last active September 23, 2017 16:42
Warsztaty "3po3" dla Insytut Dizajnu w Kielcach - podstawy HTML CSS
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<style>
body {
background-color: #251A1A;
font-family: sans-serif;
}
@ktopolski
ktopolski / slack_bot.rb
Created September 19, 2017 21:27
Minimalistic slack bot notifier approach for rails apps - useful for capistrano deploy scripts
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative '../config/boot'
require_relative '../config/environment'
require 'slack'
Slack.configure do |config|
config.token = Rails.application.secrets.slack_bot[:token]
end
@ktopolski
ktopolski / autocomplete_input.rb
Created September 19, 2017 21:25
ActiveAdmin Semantic UI Autocomplete component a.k.a. JSX in Ruby with Arbre
# app/admin/components/autocomplete_input.rb
module Components
class AutocompleteInput < Arbre::Component
builder_method :autocomplete_input
def tag_name
'li'
end
def default_class_name
@ktopolski
ktopolski / tracker.coffee
Last active September 25, 2017 15:26
Google Analytics Rails form tracker
class Tracker
constructor: ->
@success = false
@pageLeftTracked = false
trackFormChoices: ->
$formInputs = $('form section input')
$formInputs.each (index, input) =>
$(input).change =>
@ktopolski
ktopolski / strategies.rb
Last active September 19, 2017 21:15
Enumerator Strategies
# importing method
def import_items(source)
if SECTION_SOURCES.include? source.name
Strategies::SectionStrategy.items(@repository, source.id).each(&method(:import_item))
else
Strategies::ItemsStrategy.items(@repository, source.id).each(&method(:import_item))
end
end
# strategies
@ktopolski
ktopolski / banhammer.rb
Created September 19, 2017 21:02
Banning people with Rack::Attack
# Gemfile
gem 'rack-attack'
# config/application.rb
config.middleware.use Rack::Attack
# config/initializers/rack_attack.rb
BANNED_DOMAINS = %w(
google-liar.ru
@ktopolski
ktopolski / povray.vim
Last active October 24, 2015 22:29
Povray command for VIM
" compile POVRay script being currently edited, clear output and open the resulting .png ONLY when povray compilation succeeds.
command Povray !povray % && clear && feh %<.png
" delete the generated .png when exiting from .pov file of the same name.
autocmd BufWinLeave *.pov :!rm %<.png