Skip to content

Instantly share code, notes, and snippets.

import { NextApiRequest } from 'next';
// Inspired by https://github.com/myshenin/aws-lambda-multipart-parser
export interface FilePart {
type: string
filename: string
contentType: string
content: unknown
}
@webjay
webjay / datasource-layer.ts
Created October 1, 2022 11:54
@mrgrain/cdk-esbuild example
const datasourceLayer = new LayerVersion(this, id + 'DatasourceLayer', {
code: new TypeScriptCode('./src/layers/datasource/datasource.ts', {
buildOptions: {
external: [
'pg-native',
'pg',
'typeorm',
'typeorm-aurora-data-api-driver',
],
// keepNames: true,
@webjay
webjay / test.wrapHandler.js
Last active August 29, 2015 14:17
Functional wrapHandler
'use strict';
function wrapHandler (handler, callback) {
var name = arguments[0].name || 'clone';
return function (err) {
if (err) return callback(err);
console.log(name, 'called with', arguments);
var args = Array.prototype.slice.call(arguments, 1);
args.push(callback);
handler.apply(this, args);
@webjay
webjay / formpart.js
Created February 5, 2015 02:49
quoted-printable form part
'use strict';
var mimelib = require('mimelib');
var EOL = '\r\n';
module.exports = formpart;
function escapeQuotation (str) {
return str.replace(/"/g, '\"');
'use strict';
module.exports = HashTable;
function HashTable () {
this.index = [];
this.table = [];
}
HashTable.prototype = {
@webjay
webjay / whenAll.js
Created July 31, 2014 23:02
How to listen to an event on multiple objects using Backbone.js
function whenAll (objects, event, callback) {
var callbackWrapper = _.after(objects.length, callback);
_.each(objects, function (obj) {
obj.once(event, callbackWrapper, this);
}, this);
}

Keybase proof

{
    "body": {
        "key": {
            "fingerprint": "9807fcf997789f7d922b282d2ff3245ce02f2c23",
            "host": "keybase.io",
            "key_id": "2ff3245ce02f2c23",
@webjay
webjay / flinkdetoffentlige.js
Created April 30, 2014 12:40
Flink det offentlige Gignal widget
<div id="gignal-stream">
<link rel="stylesheet" href="//gignal.github.io/widget/gignal/lib/style.min.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="//platform.twitter.com/widgets.js"></script>
<script src="//gignal.github.io/widget/gignal/lib/app.min.js"></script>
<header></header>
<div id="gignal-widget" data-eventid="8GMtlyQyWN"></div>
@webjay
webjay / ping.log
Last active December 28, 2015 23:08
$ ping google.com
PING google.com (74.125.228.101): 56 data bytes
64 bytes from 74.125.228.101: icmp_seq=0 ttl=52 time=18.023 ms
64 bytes from 74.125.228.101: icmp_seq=1 ttl=52 time=81.646 ms
64 bytes from 74.125.228.101: icmp_seq=2 ttl=52 time=81.636 ms
64 bytes from 74.125.228.101: icmp_seq=3 ttl=52 time=22.099 ms
64 bytes from 74.125.228.101: icmp_seq=4 ttl=52 time=79.649 ms
64 bytes from 74.125.228.101: icmp_seq=5 ttl=52 time=78.707 ms
64 bytes from 74.125.228.101: icmp_seq=6 ttl=52 time=36.977 ms
Request timeout for icmp_seq 7
@webjay
webjay / gist:5325563
Created April 6, 2013 09:40
Redis client
var redis = require('redis');
module.exports = function () {
client = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
if (process.env.REDIS_AUTH) {
client.auth(process.env.REDIS_AUTH);
}
client.on('error', function (err) {
console.error('Redis error', err);
});