Skip to content

Instantly share code, notes, and snippets.

View pimterry's full-sized avatar

Tim Perry pimterry

View GitHub Profile
{
"log": {
"version": "1.2",
"creator": {
"name": "HTTP Toolkit",
"version": "16b657aaeff07eec548e31ccf2d5573154e287ba"
},
"pages": [
{
"id": "Curl/7.68.0",
@pimterry
pimterry / mockttp-response-rewriting.js
Created April 8, 2021 11:31
A tiny Mockttp script that creates a response-rewriting proxy using Mockttp.
const mockttp = require('mockttp');
const server = mockttp.getLocal();
server.start().then(async () => {
// This creates a proxy rule, which will forward all traffic to the real server:
await server.anyRequest().thenPassThrough({
// Every time the real server gets a response, this callback will be called:
beforeResponse: (response) => {
console.log(`Got ${response.statusCode} response with body: ${response.body.text}`);
@pimterry
pimterry / nginx.conf
Created June 10, 2020 13:16 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@pimterry
pimterry / awaitFirst.js
Created January 9, 2020 17:56
JS code (untested) to wait for the first success, or throw the last error.
const awaitFirst = (promises) =>
new Promise((resolve, reject) => {
let count = promises.length;
promises.forEach(p =>
p.then(resolve, (e) => {
count = count - 1;
if (count === 0) reject(e);
})
);
});
# Contributor License Agreement
_Closely based on [the Ghost CLA](https://github.com/TryGhost/Ghost/blob/496f873ac49cd61fd15206252e9fcdf8a7c4f7c6/.github/CONTRIBUTING.md#contributor-license-agreement)_.
Definitions: "You" means the individual or legal entity who submits a contribution, "We" or "Us" means the HTTP Toolkit open-source project (https://github.com/httptoolkit) and its manager & representative Timothy Hugh Perry (https://github.com/pimterry).
By contributing Your code to this project You grant Us a non-exclusive, irrevocable, worldwide, royalty-free, sublicenseable, transferable license under all of Your relevant intellectual property rights (including copyright, patent, and any other rights), to use, copy, prepare derivative works of, distribute and publicly perform and display the contributions on any licensing terms, including without limitation: (a) open source licenses like the MIT license; and (b) binary, proprietary, or commercial licenses. Except for the licenses granted herein, You res

A Proposal for Batched REST

An alternative to both REST & GraphQL, combining the benefits of each, based on https://tools.ietf.org/id/draft-snell-http-batch-00.html.

Batch multiple related requests into one HTTP request, which can be sent once & processed once on the server-side, but otherwise keep all the benefits of REST & HTTP. This is one single raw HTTP request:

POST /batch
Host: example.com
Content-Type: multipart/batch
Hi,
I'm afraid I'm not interested in this position right now.
I would like to know how you're getting my details and what you're storing though. Under my rights from the GDPR, can you please tell me:
* what personal data you have collected about me?
* the source of this data?
* who you've shared it with, and under what basis?
* how this data is being used?
@pimterry
pimterry / resin-set-build-by-tags.js
Last active April 13, 2018 14:04
Set the build for a set of resin.io devices by matching tag metadata
let APP_ID = ...;
let TAG_KEY = ...;
let TAG_VALUE = ...; // Remove this and its use below to ignore the value
let TARGET_ID = ...; // Build id (not commit hash)
sdk.pine.patch({
resource: 'device',
options: {
filter: {
belongs_to__application: APP_ID,
const fetch = require('node-fetch');
// Connect to the npm registry, and stream back results to the console every time a package is published
fetch('https://skimdb.npmjs.com/registry/_changes?since=now&feed=continuous&filter=_view&view=app/updated')
.then((response) => response.body.pipe(process.stdout))
fetch('https://xkcd.com/info.0.json')
.then((response) => response.json())
.then(console.log);