Skip to content

Instantly share code, notes, and snippets.

View strzibny's full-sized avatar
🏠
Working from home

Josef Strzibny strzibny

🏠
Working from home
View GitHub Profile
@strzibny
strzibny / counter_reducer.rb
Last active January 27, 2018 18:32
Ruby reducer example
counter_reducer = -> (state, action) {
state ||= 0
case action[:type]
when 'increment'
state += 1
when 'decrement'
state -= 1
else
state
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@strzibny
strzibny / README.md
Created July 15, 2016 11:45 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@strzibny
strzibny / middleware.rb
Created May 11, 2016 11:52
Rails default middleware
#!/usr/bin/env ruby
# http://guides.rubyonrails.org/v3.2.8/rails_on_rack.html
require 'rack'
require 'rails/all'
# Defaults are defined in railties/lib/rails/application/default_middleware_stack.rb
class Application < Rails::Application
routes.draw do
root to: Proc.new { [200, {'Content-Type' => 'text/html'}, ["Hello from app"]] }
end
@strzibny
strzibny / routing.rb
Created May 10, 2016 18:25
Routing with Journey
#!/usr/bin/env ruby
require 'rails'
# App definition
class Application < Rails::Application
end
# Different application with directly defined routes that we can route to as well
class DifferentApplication < Rails::Application
routes.draw do
@strzibny
strzibny / unused_routes.rb
Created May 5, 2016 15:21
Find unused routes in Rails
#!/usr/bin/env ruby
# Extracted from traceroute gem + checking the presence of views as well
require_relative './config/environment.rb'
class Traceroute
def initialize(app)
@app = app
end
#!/usr/bin/env ruby
require 'rubydns'
INTERFACES = [
[:udp, "0.0.0.0", 53],
[:tcp, "0.0.0.0", 53]
]
Name = Resolv::DNS::Name
IN = Resolv::DNS::Resource::IN
@strzibny
strzibny / gist:82c8c6e1608e1e40bea0
Last active August 29, 2015 14:23
gem-compare rake task example
# From Rakefile, expects :build task
task :clean do
`rm -rf pkg`
end
# Compare latest release with current git head
require 'rubygems/comparator'
task compare: [:clean, :build] do
git_version = VagrantPlugins::Registration::VERSION
@strzibny
strzibny / gist:6505c3408e995f1e380f
Last active August 29, 2015 14:04
Check what kind of spec data are saved in Marshal.4.8.Z
#!/usr/bin/ruby
# Check what kind of spec data are saved in http://rubygems.org/Marshal.4.8.Z
require 'rubygems'
require 'pp'
# wget http://rubygems.org/Marshal.4.8.Z if needed
gems = Marshal.load(Gem.inflate(File.read("./Marshal.4.8.Z")))
SPEC_PARAMS = %w[ author authors name platform require_paths rubygems_version summary
license licenses bindir cert_chain description email executables
@strzibny
strzibny / gist:7136890
Created October 24, 2013 13:04
Patch for zzak's rdoc-4.0 branch of sdoc
From 3ee81e3239f4408c38f57b35344dbd424e7eab1d Mon Sep 17 00:00:00 2001
From: Josef Stribny <[email protected]>
Date: Thu, 24 Oct 2013 14:48:46 +0200
Subject: [PATCH] Fix: Rename searchindex.rhtml file
---
lib/rdoc/generator/template/sdoc/search_index.rhtml | 8 ++++++++
lib/rdoc/generator/template/sdoc/searchindex.rhtml | 8 --------
2 files changed, 8 insertions(+), 8 deletions(-)
create mode 100644 lib/rdoc/generator/template/sdoc/search_index.rhtml