Skip to content

Instantly share code, notes, and snippets.

@psaia
psaia / observer.ts
Last active October 6, 2019 04:06
A typescript observer class with async/await capabilities.
/**
* A decent observer class.
*/
export type PayloadFn = (payload?: any) => void | Promise<void>;
export interface Subscription {
name: string;
fn: PayloadFn;
}
@psaia
psaia / wiredtiger
Created November 21, 2018 17:25
Syncing wiredtiger data with mongodb docker image
docker run --rm -P -v ~/Desktop/test/prod0-shard-0-1538600622-5bb55f5aff7a255af95eba75/:/data/db mongo:3.4
@psaia
psaia / appname.js
Last active February 19, 2018 03:35
Relay Modern (or anything else) server side rendering for bots.... only.
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const express = require("express");
const jsdom = require("jsdom");
const isBot = require("isbot");
const { Script } = require("vm");
const app = express();
@psaia
psaia / golang-style.sh
Last active September 11, 2017 23:58
Enable idiomatic "golang style" unit testing in node.js with mocha. Add this to npm's scripts or your pipeline.
#!/bin/sh
NODE_ENV=test mocha --recursive ./**/*_test.js
f=$(date +%Y-%m-%d-%H-%M-%S)
dest=$(realpath $(pwd)/..)
# Archive newly deployed files in the releases directory.
cp -R $dest/.tmp/ $dest/releases/$n
# Update the symlink to point to the latest release (atomic).
ln -sfn $dest/releases/$n $dest/live-app
# Clean up.
const zoomScale = [ // [ radius, min points ]
[0, 10],
[0.9, 10], // 1
[0.7, 10], // 2
[0.6, 10], // 3
[0.5, 10], // 4
[0.4, 9], // 5
[0.3, 8], // 6
[0.13, 3], // 7
[0.09, 3], // 8
const dummyData = [
{
name: 'Hot Pot',
images: [
'http://lorempixel.com/400/400/food/1/'
]
},
{
name: 'Hot Pot 2',
images: [
@psaia
psaia / trump.json
Created May 19, 2017 19:29
english2trump
{
"nouns": [
"Proclamation",
"Getting",
"ready",
"trip",
"Will",
"American",
"I",
"President",
@psaia
psaia / Pagination.js
Last active April 25, 2017 14:17
Example of a dynamic handler for relay/graphql cursor based pagination. This is ideal for when you have multiple paginations happening in one view. Bootstrap's pagination component is being used, but it could be any.
// An example of the configured Pagination component.
// I've injected the total in the connection on the server side.
<Pagination
bsSize="small"
items={Math.ceil(total / PAGE_COUNT)}
activePage={currentPage}
onSelect={this.onPageChange('mangosCurrentPage', 'mango', edges)}
/>
#!/usr/bin/env node
/**
* Process the client side application using babelify and browserify.
*/
if (!process.env.CLIENT_PATH || !process.env.SERVER_PATH) {
throw 'CLIENT_PATH and SERVER_PATH is required.'
}