Skip to content

Instantly share code, notes, and snippets.

Avatar

Karol Topolski ktopolski

View GitHub Profile
@ktopolski
ktopolski / povray.vim
Last active Oct 24, 2015
Povray command for VIM
View povray.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
@ktopolski
ktopolski / banhammer.rb
Created Sep 19, 2017
Banning people with Rack::Attack
View banhammer.rb
# 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 / strategies.rb
Last active Sep 19, 2017
Enumerator Strategies
View strategies.rb
# 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 / tracker.coffee
Last active Sep 25, 2017
Google Analytics Rails form tracker
View tracker.coffee
class Tracker
constructor: ->
@success = false
@pageLeftTracked = false
trackFormChoices: ->
$formInputs = $('form section input')
$formInputs.each (index, input) =>
$(input).change =>
@ktopolski
ktopolski / autocomplete_input.rb
Created Sep 19, 2017
ActiveAdmin Semantic UI Autocomplete component a.k.a. JSX in Ruby with Arbre
View autocomplete_input.rb
# 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 / slack_bot.rb
Created Sep 19, 2017
Minimalistic slack bot notifier approach for rails apps - useful for capistrano deploy scripts
View slack_bot.rb
#!/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 / index.html
Last active Sep 23, 2017
Warsztaty "3po3" dla Insytut Dizajnu w Kielcach - podstawy HTML CSS
View index.html
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<style>
body {
background-color: #251A1A;
font-family: sans-serif;
}
@ktopolski
ktopolski / simplecov_merge.rb
Last active Jun 27, 2019
merge simplecov results
View simplecov_merge.rb
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 }
You can’t perform that action at this time.