Skip to content

Instantly share code, notes, and snippets.

@tspecht
tspecht / file1.txt
Last active March 16, 2018 13:59
Created via API
$(cat plot.html)
'use strict';
var http = require('http');
// Handler called on Origin Request event by CloudFront.
// Copies the original URI header to a custom header field and rewrites the request to fetch /index.html as the application we are serving is a SPA.
module.exports.metaTagOriginRequestRewriter = (event, context, callback) => {
const request = event.Records[0].cf.request;
request.headers["x-dubsmash-uri"] = [{key: "X-Dubsmash-URI", value: request.uri}];
request.uri = "/index.html";
'use strict';
var http = require('http');
module.exports.metaTagOriginRequestRewriter = (event, context, callback) => {
const request = event.Records[0].cf.request;
request.headers["x-dubsmash-uri"] = [{key: "X-Dubsmash-URI", value: request.uri}];
request.uri = "/index.html";
callback(null, request);
};
@tspecht
tspecht / bi_directional_relay_style_cursor_based_pagination.js
Last active June 23, 2021 16:13
Bi-directional Relay-style cursor-based pagination example
import PropTypes from 'prop-types';
import React from 'react';
import {Pager} from 'react-bootstrap';
import gql from 'graphql-tag';
import {graphql} from 'react-apollo';
const PokemonQuery = gql`
query Pokemons($trainerID: Int!, $first: Int, $after: String) {
pokemons(trainerID: $trainerID, first: $first, after: $after) {
@tspecht
tspecht / example_relay_style_cursor_based_pagination.grapqhl
Last active July 28, 2017 09:18
Example of relay-style cursor-based pagination in GraphQL
query Pokemons($trainerID: Int!, $first: Int, $after: String) {
pokemons(trainerID: $trainerID, first: $first, after: $after) {
edges {
cursor
node {
id
name
species {
name
}
@tspecht
tspecht / example_cursor_based_pagination.grapqhl
Created July 28, 2017 09:15
Example of cursor-based pagination in GraphQL
query Pokemons($trainerID: Int!, $cursor: String) {
pokemons(trainerID: $trainerID, cursor: $cursor) {
id
name
species {
name
}
# ...
}
}
@tspecht
tspecht / example_offset_based_pagination.grapqhl
Created July 28, 2017 09:10
Example of offset-based pagination in GraphQL
query Pokemons($trainerID: Int!, $offset: Int, $limit: Int) {
pokemons(trainerID: $trainerID, offset: $offset, limit: $limit) {
id
name
species {
name
}
# ...
}
}
@tspecht
tspecht / email_validation.py
Last active July 4, 2017 14:10
Email validation
@app.route('/validate', methods=['GET'])
def validate():
email = request.args.get('email', '')
# Do some basic regex validation first
match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', email)
if match == None:
abort(400)
# Extract the host