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
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, " "));
}
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 September 25, 2020 11:34 — forked from GustavoCaso/job_scheduler_using_ractor.rb
Simple implementation for a job scheduler using ruby Ractor primitive
require 'optparse'
require 'json'
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'redis'
gem 'oj'
end
@strzibny
strzibny / Gemfile
Created June 25, 2020 03:48 — forked from dhh/Gemfile
HEY's 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 October 26, 2018 17:33 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
@strzibny
strzibny / todos_reducer.rb
Created January 27, 2018 18:14
Example todo reducer
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 January 27, 2018 18:12
Combining reducers into one
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 January 27, 2018 18:07
Basic ReduxStore implemented in Ruby
class ReduxStore
attr_reader :current_state
def initialize(reducer)
@reducer = reducer
@listeners = []
@current_state = nil
dispatch({})
end
@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