Skip to content

Instantly share code, notes, and snippets.

View ZempTime's full-sized avatar

Chris Zempel ZempTime

View GitHub Profile
@ZempTime
ZempTime / xstate-getting-started.md
Last active September 12, 2019 07:25
Statechart doc example

Thinking in State Charts

  1. Determine your states
  2. Determine your events
  3. Determine your side effects (resulting changes in state)

You can store information in two ways:

  • State nodes (each state node can have one value)
  • Context (can hold arbitrary values because js object)
@ZempTime
ZempTime / lit-upgrade.md
Last active November 7, 2018 15:45
Lit Upgrade
@ZempTime
ZempTime / polymer 3 & redux forms.md
Last active May 14, 2018 03:05
Exploration of forms in redux

How should we handle linking up forms with a redux store in polymer 3?

This gist is my attempt to do a couple things:

  • Articulate the problem
  • Begin aggregating relevant existing solutions or things we could use
  • Define desired solutions that may or may not exist in usable forms

Problem Articulation

@ZempTime
ZempTime / generate_index.rb
Created October 6, 2017 15:03
Building out index.js files throughout app
require "pathname"
IGNORED_FILES = ['.DS_Store']
def recurse(directory)
current_dir = Pathname.new(directory)
populate_index(current_dir)
current_dir.children.each do |dir|
recurse(dir) if dir.directory?
@ZempTime
ZempTime / LocalStorage.rb
Last active September 12, 2017 17:57
little nested helper class to store some state locally in yaml since the aws-sdk v2 for ruby doesn't support tagging, and thats what we gotta use
require "yaml"
class LocalStorage
class DocumentIdAlreadyExists < StandardError; end
class DocumentKeyAlreadyExists < StandardError; end
# YAML format per-environment
# env: {
# corrected_doc_ids: [],
# corrected_doc_keys: [],
# destroyable_doc_keys:[]
@ZempTime
ZempTime / processes_controller.rb
Created July 26, 2017 21:55
Controller Setups
module Api
module V2
module Investments
class ProcessesController < Api::V2::BaseController
include InvestmentScoped
def index
end
def show
@ZempTime
ZempTime / translation.rb
Last active July 19, 2017 22:54
Translation Model
# pseudocode
# assuming message is set by the teacher, and isn't stored on a 1-1 message/parent basis
# but a 1 message - many parents basis
class Message < ActiveRecord::Base
has_many :translations
def translated_message(language_code='en')
translation = translations.where(language_code: language_code).first
if translation
@ZempTime
ZempTime / scraping_ideas.rb
Last active August 11, 2016 15:41
Page Scraping Logic/Ideas
# from http://blog.rubyroidlabs.com/2016/04/web-scraping-2/
def strip_bad_chars(text)
text.gsub!(/"/, "'");
text.gsub!(/\u2018/, "'");
text.gsub!(/[”“]/, '"');
text.gsub!(/’/, "'");
text
end
class @RealtimeForm
constructor: (form) ->
@form = $(form)
@behavior = @form.data("realtime")
@monitorInputs()
monitorInputs: =>
@radio_inputs = new RadioGroupInput @form.find(":radio"), @behavior
@inputs = $.map @form.find(":input").not(":input[type=submit]").not(":input[type=radio]"), (input, i) =>
new TextyInput(input, @behavior)
@ZempTime
ZempTime / weight_formatter.rb
Last active August 29, 2015 14:22
Weight Formatter
class WeightFormatter
PROCESSABLE_WEIGHT_UNITS = ["grams", "ounces"]
def self.call(weight_unit, weight)
unless PROCESSABLE_WEIGHT_TYPES.include?(weight_unit)
return "#{weight} #{weight_unit}"
end
send("process_#{weight_unit.downcase}", weight)
end