Skip to content

Instantly share code, notes, and snippets.

View JohnAmican's full-sized avatar
🎯
Focusing

John Amicangelo JohnAmican

🎯
Focusing
View GitHub Profile
WITH q AS (
SELECT id,
root_id,
version,
lag(version) OVER (PARTITION BY root_id ORDER BY root_id, version) as prev_version,
lead(version) OVER (PARTITION BY root_id ORDER BY root_id, version) as next_version,
latest
FROM trades
ORDER BY root_id, version
)
UPDATE trades SET latest = false where root_id = 'foo' AND version = 5; -- Client 1
UPDATE trades SET latest = false where root_id = 'foo' AND version = 5; -- Client 2
INSERT INTO trades (latest, root_id, version) VALUES (true, 'foo', 6); -- Client 1
INSERT INTO trades (latest, root_id, version) VALUES (true, 'foo', 6); -- Client 2, UNIQUENESS CONSTRAINT ERROR!
BEGIN;
UPDATE trades SET latest = false where root_id = 'foo' AND version = 5;
INSERT INTO trades (latest, root_id, version) VALUES (true, 'foo', 6);
COMMIT;
CREATE TABLE trades
(
id SERIAL NOT NULL CONSTRAINT trades_pkey PRIMARY KEY,
latest BOOLEAN NOT NULL,
root_id TEXT NOT NULL,
version INTEGER NOT NULL,
price INT
);
CREATE UNIQUE INDEX trades_root_id_and_version ON trades (root_id, version);
React = require 'react'
app = require './app'
module.exports = (data) -> React.renderToString app(data)
module React
module Server
module Rendering
extend ActiveSupport::Concern
include ::BeforeRender
included do
before_render :set_rendered
attr_reader :rendered
bundle 'server.js',
entries: ["your/entry/file.cjsx"]
extensions: ['.coffee', '.cjsx']
builtins: false # already in node
commondir: false # already in node
detectGlobals: false # already in node
browserField: false # already in node
standalone: 'render'
gulp.task 'frontend-js', ->
bundle 'application.js',
entries: ["your/entry/file.cjsx"] # or `.coffee` or whatever
extensions: ['.coffee', '.cjsx']
debug: true
bundle = (name, opts) ->
_.extend opts,
fullPaths: true
cache: {}
packageCache: {}
b = browserify opts
rebundle = ->
b.bundle()