Skip to content

Instantly share code, notes, and snippets.

CREATE TABLE board(id serial primary key, moves int[]);
INSERT INTO board(moves) values('{0,0,0}');
WITH current AS (SELECT generate_series(1,3) p_no, unnest(moves) "pos" FROM board order by id desc LIMIT 3),
roll AS (SELECT generate_series(1,3) p_no, round(random()*2)+1 result),
move AS (SELECT coalesce('{"9":"2","3":"6"}'::json->>(c.pos+r.result)::text, (c.pos+r.result)::text)::int "new_pos", c.pos "old_pos"
FROM current c JOIN roll r ON c.p_no = r.p_no),
constrained_move AS (SELECT (CASE WHEN m.new_pos > 10 THEN m.old_pos
WHEN m.new_pos < 10 THEN m.new_pos
ELSE 10 END) "final_pos" FROM move m),
rec AS (INSERT INTO board(moves) (SELECT array_agg(cm.final_pos) FROM constrained_move cm))
@bhavinkamani
bhavinkamani / jspm.browser.js
Last active February 14, 2016 13:21
jspm_17 config files
SystemJS.config({
baseURL: "/",
production: true,
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*",
"vendor/": "src/vendor/",
"jspm_17/": "src/"
},
bundles: {
@bhavinkamani
bhavinkamani / index.html
Created February 15, 2016 10:30
http2 jspm config files
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="application/xhtml+xml">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=PT+Sans|PT+Sans+Caption' rel='stylesheet' type='text/css'>
<style type="text/css">
html, body {
margin: 0 auto;
@bhavinkamani
bhavinkamani / kafka_error.log
Created September 3, 2019 16:16
kafka installation error log with docker machine and parallels driver
===> ENV Variables ...
ALLOW_UNSIGNED=false
COMPONENT=kafka
CONFLUENT_DEB_VERSION=1
CONFLUENT_MAJOR_VERSION=5
CONFLUENT_MINOR_VERSION=1
CONFLUENT_MVN_LABEL=
CONFLUENT_PATCH_VERSION=2
CONFLUENT_PLATFORM_LABEL=
CONFLUENT_VERSION=5.1.2