Skip to content

Instantly share code, notes, and snippets.

@tomduncalf
tomduncalf / gist:00070fecb68a6cf35c0102c75f166a8a
Created March 3, 2020 08:33
app.js gist for running react-static dev server with Phusion Passenger
const pkg = require('react-static/package.json');
let packageConfig = {};
try {
packageConfig = require(path.resolve(process.cwd(), 'package.json'));
packageConfig = packageConfig['react-static'] || {};
} catch (err) {
}
const argv = {};
@tomduncalf
tomduncalf / interactionObserver.ts
Last active January 17, 2019 17:01
React Interaction Observer scroll
interface IState {
sticky: boolean;
}
export class HeaderBar extends React.Component<{}, IState> {
sentinelRef: React.RefObject<HTMLDivElement>;
observer: IntersectionObserver;
state = { sticky: false };
@tomduncalf
tomduncalf / index.html
Last active November 3, 2017 13:56
Close test
<button id="close">close me</button>
<script>
document.getElementById('close').addEventListener('click', function() {
alert(1);
window.close();
});
</script>
@tomduncalf
tomduncalf / line.js
Last active October 25, 2017 10:54
Drawing a straight line using a shader with regl
const drawLine = regl({
frag: `
precision mediump float;
uniform vec4 color;
void main() {
gl_FragColor = color;
}`,
vert: `
precision mediump float;
@tomduncalf
tomduncalf / example.js
Last active December 17, 2022 02:52
How to upload a local (iOS filesystem) file to S3 using React Native with temporary credentials
/**
* I recently needed to upload a file from the phone's filesystem to S3 using temporary credentials
* (i.e. access key, secret key and session token) issued by an API for a React Native application,
* without the overhead of Base64 encoding the file and passing it over the bridge (as it could be
* several MB big), and wanted to avoid writing native code to do this.
*
* None of the S3 libraries online worked with the temporary credentials, but I figured out a
* solution using the official AWS SDK (which is good, as it supports all the relevant authentication
* out of the box) and the react-native-fetch-blob module, which allows you to upload directly from the
* filesystem with the correct Content-type header (as far as I can tell, React Native's fetch only
var webpack = require('webpack');
var path = require('path');
var WebpackNotifierPlugin = require('webpack-notifier');
module.exports = {
devtool: 'eval',
entry: [
// Add the react hot loader entry point - in reality, you might only want this in your dev config
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000',
{ "Test": 1 }
{"country":"England","result_count":1665,"longitude":-0.0651563649706527,"area_name":" E8","listing":[{"image_caption":"","status":"for_sale","num_floors":"0","listing_status":"sale","num_bedrooms":"2","agent_name":"Hollyton","latitude":51.524952,"agent_address":"42 Upper Berkeley Street, London","num_recepts":"0","property_type":"Flat","country":null,"longitude":-0.087046,"first_published_date":"2015-09-24 11:35:48","displayable_address":"City Road, Bezier Apartments EC1Y","floor_plan":["http://lc.zoocdn.com/b2b23e06251cd544a4907209b70fef3476a36d90.jpg"],"street_name":"","num_bathrooms":"0","thumbnail_url":"http://li.zoocdn.com/80c74240b27c6eea5ce36fe74205d9be8a57c993_80_60.jpg","description":"This stunning 2 bedroom, 3 bathroom penthouse apartment set on the 14th floor of the new development- Bezier Apartments by renowned developers City House Development Ltd. This property consists of a bright open-plan reception room attached to an ultra-modern fitted kitchen that caters to all needs with generous storage
@tomduncalf
tomduncalf / destructure.ts
Created November 13, 2015 09:23
Function to emulate the ES7 destructuring with spread operator behaviour in Typescript
/**
* Return a copy of `obj` with the specified properties removed
* Modified from Babel source code
*/
function objectWithoutProperties (obj: Object, keys: string[]): any {
let target = {}
for (var i in obj) {
if (keys.indexOf(i) >= 0) { continue }
if (!Object.prototype.hasOwnProperty.call(obj, i)) { continue }
target[i] = obj[i];
@tomduncalf
tomduncalf / gist:8077681a597c9bc3b8ab
Last active August 29, 2015 14:14
Attempt at a custom Jasmine matcher for ES6 Map equality testing, using the spread operator
import cfg from '../lib/config-parser';
var customMatchers = {
toEqualMap: (util, customEqualityTesters) => {
return {
compare: (actual, expected) => {
var result = {};
result.pass = util.equals([...actual], [...expected], customEqualityTesters);
if(!result.pass) {