Skip to content

Instantly share code, notes, and snippets.

View dupski's full-sized avatar

Russell Briggs dupski

  • United Kingdom
View GitHub Profile
@dupski
dupski / pg11.sh
Created June 27, 2020 12:19
Shell script to start PostgreSQL 11 in a docker container
#!/bin/bash
echo "Starting PostgreSQL 11..."
docker run -it --rm \
-e POSTGRES_PASSWORD=mysecretpassword \
-v postgres11-data:/var/lib/postgresql/data \
-p 5432:5432 \
postgres:11
@dupski
dupski / readable-string.ts
Last active July 14, 2019 00:32
Simple NodeJS class for creating a Readable Stream from a String
import { Readable } from 'stream'
class ReadableString extends Readable {
private sent = false
constructor(private str: string) {
super();
}
_read() {
import * as TestRenderer from 'react-test-renderer';
let renderer: TestRenderer.ReactTestRenderer;
let instance: TestRenderer.ReactTestInstance;
beforeAll(() => {
renderer = TestRenderer.create(
<div>
<h2>My Super-sweet Component</h2>
<SomeComponent />
@dupski
dupski / quote_generator.js
Created May 26, 2018 22:57
Awesome Quote Generator v1.5
console.log(`Welcome to Briggsy's Awesome Quote Generator v1.5!`);
(async () => {
for (let i=0; i<3; i++) {
await getUserQuote();
}
console.log('Profit!');
@dupski
dupski / quote_generator.js
Created May 26, 2018 22:43
Awesome Quote Generator v1.0
console.log(`Welcome to Briggsy's Awesome Quote Generator!`);
(async () => {
await getUserQuote();
await getUserQuote();
await getUserQuote();
console.log('Profit!');
})();
@dupski
dupski / async_example.js
Created May 26, 2018 22:03
ES2017 Async Function example
import request from 'axios';
async function getUserQuote() {
const userResponse = await request({ url: 'https://randomuser.me/api/', responseType: 'json' });
console.log('Got User:', response.data);
const quoteResponse = await request({ url: 'http://quotes.rest/qod.json', responseType: 'json' });
console.log('Got Quote:', response.data);
@dupski
dupski / promise_example.js
Created May 26, 2018 21:35
Modern Promise Example
import request from 'axios';
function getUserQuote() {
return request({ url: 'https://randomuser.me/api/', responseType: 'json' })
.then((response) => {
console.log('Got User:', response.data);
return request({ url: 'http://quotes.rest/qod.json', responseType: 'json' });
})
.then((response) => {
console.log('Got Quote:', response.data);
@dupski
dupski / server_with_data.ts
Last active May 19, 2018 23:55
Create a GraphQl API in 5 minutes - load demo data
import { createDemoData } from './models';
...
console.log(`Server is running at http://localhost:${config.port}/`);
createDemoData().then(() => {
console.log('Demo Data Loaded!')
});
@dupski
dupski / models_with_data.ts
Created May 19, 2018 23:51
Create a GraphQL API in 5 minutes - demo data
export async function createDemoData() {
const user1 = (
await modelManager.create(new User({
full_name: 'Russell Briggs',
email: '[email protected]'
}))
).result;
const user2 = (
await modelManager.create(new User({
@dupski
dupski / routes.ts
Created May 19, 2018 23:19
Create a GraphQL API in 5 minutes - routes
import * as Koa from 'koa';
import * as KoaRouter from 'koa-router';
import { api } from './models';
import { graphqlKoa, graphiqlKoa } from 'apollo-server-koa';
export function registerRoutes(app: Koa) {
const router = new KoaRouter();
const schema = api.getGraphQLSchema();