Skip to content

Instantly share code, notes, and snippets.

@jameswragg
jameswragg / labelledPromises.js
Last active September 6, 2023 09:25
Promise.allSettled with Object keys
/**
* Resolves all Promises from a key/val object, returning the same structure but resolved
* @param {Object.<string, (function)>} obj - An object with any number of key-value pairs.
* @returns {{ values: object, rejected: object }}
*/
const labelledPromises = async (obj) => {
const keys = Object.keys(obj);
const promises = Object.values(obj);
const results = await Promise.allSettled(promises);
@jameswragg
jameswragg / .editorconfig
Last active February 20, 2023 13:23
Node project defaults
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
@jameswragg
jameswragg / index.js
Last active January 11, 2021 14:24
Using trumpet to read/modify/write the IncomingMessage stream in @hapi/h2o2
const Hapi = require("@hapi/hapi");
const H2o2 = require("@hapi/h2o2");
const { PassThrough } = require("stream");
const trumpet = require("trumpet");
const start = async function () {
const server = Hapi.server({
host: "localhost",
port: 8000,
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://mozilla.github.io/nunjucks/files/nunjucks.min.js"></script>
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<title> </title>
<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<![endif]-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
POST /restapi/users/storedcv/save/ HTTP/1.1
Host: researchjobfinder-webservice.madgexjb.com
Content-Type: multipart/form-data; boundary=----myRandomBoundary12345
Accept: */*
Connection: keep-alive
Content-Length: 53383
User-Agent: MadgexReleaseApp/com.madgex.researchjobs (4002100135; OS Version 10.0.1 (Build 14A403))
Accept-Language: en-GB;q=1.0,da-GB;q=0.9
Authorization: OAuth oauth_token="b55a0b37-d813-4815-823d-58562266adcf", oauth_nonce="5403445C-A10D-40CF-8895-07661B32C4AA", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="1CA260F7-2FCC-4116-8C3E-F79B89BF8906", oauth_timestamp="1474382335", oauth_version="1.0", oauth_signature="eSyL3rCduYf0pblaTzZxcWkBYso%3D"
Accept-Encoding: gzip, deflate
@jameswragg
jameswragg / SassMeister-input.scss
Last active August 29, 2015 14:15
Generated by SassMeister.com.
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
// Example SCSS file
$primaryColor: #eeffcc;
$container-width: 100%;
// consume variables
# grunt-init gruntplugin
# npm install
# grunt
module.js:340
throw err;
^
Error: Cannot find module 'minimatch'
at Function.Module._resolveFilename (module.js:338:15)
@jameswragg
jameswragg / gist:1329382
Created October 31, 2011 23:19
selectRow fails in long TableViews
// create table view data object
var data = [
{title:'Row 1'},
{title:'Row 2'},
{title:'Row 3'},
{title:'Row 4'},
{title:'Row 5'},
{title:'Row 6'},
{title:'Row 7'},
{title:'Row 8'},
@jameswragg
jameswragg / gist:1319241
Created October 27, 2011 10:32
Orientationchange event oddities
var orientation = getOrientation(),
newOrientation;
Titanium.Gesture.addEventListener('orientationchange', function(e){
if (e.orientation == Titanium.UI.PORTRAIT || e.orientation == Titanium.UI.UPSIDE_PORTRAIT){
newOrientation = 'portrait';
}else if(e.orientation == Titanium.UI.LANDSCAPE_LEFT || e.orientation == Titanium.UI.LANDSCAPE_RIGHT){
newOrientation = 'landscape';