Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Josef Strzibny strzibny

🏠
Working from home
View GitHub Profile
View attribution.js
https://jennamolby.com/how-to-use-cookies-to-capture-url-parameters/
// Parse the URL
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
var results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
View react-controller.js
import { Controller } from 'stimulus';
import React from 'react';
import ReactDOM from 'react-dom';
import AppContainer from 'components/core/AppContainer';
export default class extends Controller {
connect() {
const Component = window.ReactComponents[this.data.get('component')];
let props = this.data.get('props') || {};
if (typeof props === 'string') {
@strzibny
strzibny / job_scheduler_using_ractor.rb
Created Sep 25, 2020 — forked from GustavoCaso/job_scheduler_using_ractor.rb
Simple implementation for a job scheduler using ruby Ractor primitive
View job_scheduler_using_ractor.rb
require 'optparse'
require 'json'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'redis'
gem 'oj'
end
@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