Skip to content

Instantly share code, notes, and snippets.

@sergueif
sergueif / tabs.html
Last active November 30, 2020 00:14
<div>
<div class="tabs">
<div class="switchy-tab active" data-section-id="section1">tab1</div>
<div class="switchy-tab" data-section-id="section2">tab2</div>
<div class="switchy-tab" data-section-id="section3">tab3</div>
</div>
<div className="sections">
<div class="switchy-section active" id="section1">stuff 1 </div>
<div class="switchy-section" id="section2">stuff 2</div>
module Services
class UserService
#command is an "ActiveModel"
def apply_command(user_id, command)
aggregate = UserAggregate.find_or_create_by_id!(user_id)
aggregate.with_lock do
user = user_value(aggregate)
event = command.apply(user)
new_user = event.apply(user)
@sergueif
sergueif / imperative.rb
Last active September 2, 2019 23:41
Genuenly asking: What are some versatile patterns for making imperative code more functional/testable?
# can arbitrary imperative code be chopped up into a loop with a functional step?
# "comm" indicates some communication to an external computer or otherwise side-effecty step
# order of them presumably matters
# code is made up. It's an arbitrary collection of steps and "if" statements
# BUT! it's very similar to actual code I found at the office. :) #java
# Note: I think the following transformation is harder in typed langs.
# I wish not to deal with that at the moment. Will accept any chance no matter how verbose or clunky.
@sergueif
sergueif / create_value_records.rb
Last active June 5, 2019 22:47
Value persistence across active records with lazy-loading
class CreateValueRecords < ActiveRecord::Migration[5.1]
def change
create_table :value_records, id: false do |t|
t.jsonb :body, null: false, default: {}
t.string :key
t.timestamps
end
execute "ALTER TABLE value_records ADD PRIMARY KEY (key);"
end
@sergueif
sergueif / create_stickman_versions.rb
Last active May 28, 2019 13:20
Versioned state with optimistic concurrency in Rails. Domain model: Stickmen have bank accounts and accumulate money. See my blog post to learn more.
class CreateStickmanVersions < ActiveRecord::Migration[5.1]
def change
create_table :stickman_versions do |t|
t.references :stickman, foreign_key: true
t.integer :version, null: false, default: 0
t.jsonb :body, null: false, default: {}
t.jsonb :debug, default: {}
t.timestamps
t.index [:stickman_id, :version], unique: true
end
@sergueif
sergueif / pair-programming-companies-in-toronto.txt
Last active April 2, 2018 14:12
Pair Programming Companies in Toronto
Autonomic
Pivotal CF
Pivotal Labs
Tribalscale
Connected Labs
Helpful
Taplytics
@sergueif
sergueif / ar_to_value_take2.rb
Created April 17, 2016 22:12
Active Record to Value (take 2)
class Account < ActiveRecord::Base
#id integer
#first_name string
#last_name string
class Value
include Virtus.value_object
attribute :id, Integer
attribute :first_name, String
@sergueif
sergueif / ar_to_value_take1.rb
Created April 17, 2016 22:05
ActiveRecord to Value
class Account < ActiveRecord::Base
#id integer
#first_name string
#last_name string
class Value < Struct.new(:id, :first_name, :last_name)
end
def as_value
mkdir -p www/fedwiki/wiki
cd www/fedwiki/wiki
sudo apt-get update
sudo apt-get install npm
npm install wiki
sudo nodejs node_modules/.bin/wiki --port 80 --url YOUR_DOMAIN_NAME
#CTRL-C the wiki to stop it once its running
printf 'YOUR_MOZILLA_PERSONA_EMAIL' > ~/.wiki/status/persona.identity #super important to use printf instead of echo
sudo nodejs node_modules/.bin/wiki --port 80 --url YOUR_DOMAIN_NAME #keep this running forever by any means you like
@sergueif
sergueif / checklist.html
Created January 9, 2016 00:57
checklist.html
<div>
<div>function(type, change) {</div>
<div>
<textarea id='code' style="width: 49%; height: 300px;"></textarea>
<textarea id='changes' style="width: 49%; height: 300px;"></textarea>
</div>
<div>}</div>
<input id="go" type="submit" onClick="go()" />
<div id="checklist"></div>