Skip to content

Instantly share code, notes, and snippets.

Josef Strzibny strzibny

View GitHub Profile
@strzibny
strzibny / Gemfile
Created Jun 25, 2020 — forked from dhh/Gemfile
HEY's Gemfile
View Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@strzibny
strzibny / stimulus.md
Created Oct 26, 2018 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
View stimulus.md
@strzibny
strzibny / todos_reducer.rb
Created Jan 27, 2018
Example todo reducer
View todos_reducer.rb
todos_reducer = -> (state, action) {
state ||= []
case action[:type]
when 'add'
state.push(action[:todo])
when 'remove'
state.remove(action[:todo])
else
state
@strzibny
strzibny / combine_reducers.rb
Created Jan 27, 2018
Combining reducers into one
View combine_reducers.rb
class ReduxStore
def self.combine_reducers(reducers)
-> (state, action) {
state ||= {}
reducers.reduce({}) { |next_state, (key, reducer)|
next_state[key] = reducer.call(state[key], action)
next_state
}
}
@strzibny
strzibny / redux_store.rb
Last active Jan 27, 2018
Basic ReduxStore implemented in Ruby
View redux_store.rb
class ReduxStore
attr_reader :current_state
def initialize(reducer)
@reducer = reducer
@listeners = []
@current_state = nil
dispatch({})
end
@strzibny
strzibny / counter_reducer.rb
Last active Jan 27, 2018
Ruby reducer example
View counter_reducer.rb
counter_reducer = -> (state, action) {
state ||= 0
case action[:type]
when 'increment'
state += 1
when 'decrement'
state -= 1
else
state
View gist:01b3e3d00f3d05f7761da496d06d941b
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 Jul 15, 2016 — forked from hofmannsven/README.md
My simply Git Cheatsheet
@strzibny
strzibny / middleware.rb
Created May 11, 2016
Rails default middleware
View middleware.rb
#!/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
Routing with Journey
View routing.rb
#!/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
You can’t perform that action at this time.