Skip to content

Instantly share code, notes, and snippets.

@mattfysh
mattfysh / utils.js
Created December 13, 2012 00:22
Tap listener
window.utils = (function() {
function touch(el, type, listener) {
if (type === 'tap') {
var isDragging, startPos;
function touchStart(e) {
el.addEventListener('touchmove', touchMove);
el.addEventListener('touchend', touchEnd);
isDragging = false;
@mattfysh
mattfysh / main.cpp
Created February 1, 2020 07:15
Runtime symbols
#include <iostream>
using namespace std;
template<typename T>
T make_symbol(T value, string metadata);
template<typename T>
string get_symbol_for(T value);
env:
node: true
es6: true
parserOptions:
ecmaVersion: 2020
sourceType: module
extends:
- airbnb-base
import { onMount } from 'svelte';
function noop() { }
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
@mattfysh
mattfysh / client.js
Last active June 7, 2023 14:45
urql + auth-exchange + aws-amplify
import { makeOperation } from '@urql/svelte'
import { authExchange } from '@urql/exchange-auth'
import { Auth } from 'aws-amplify'
import produce from 'immer'
import { set } from 'lodash'
const amplifyAuthExchange = authExchange({
addAuthToOperation: ({ authState, operation }) => {
if (!authState?.token) {
return operation
@mattfysh
mattfysh / 5reqs.sh
Last active July 18, 2021 23:15
Luminati Performance
PROXY_URL=<your_proxy_url>
echo "HTTP"
time (
curl --proxy $PROXY_URL -s -o /dev/null http://example.com
curl --proxy $PROXY_URL -s -o /dev/null http://example.com
curl --proxy $PROXY_URL -s -o /dev/null http://example.com
curl --proxy $PROXY_URL -s -o /dev/null http://example.com
curl --proxy $PROXY_URL -s -o /dev/null http://example.com
)
@mattfysh
mattfysh / 1-before.js
Last active August 10, 2021 23:21
Shouty Stream
const { Transform } = require('stream')
const { createGzip } = require('zlib')
const fs = require('fs')
const testfile = fs.createWriteStream('test.gz')
const createShoutyStream = () => new Transform({
construct(cb) {
this.data = ''
cb()
@mattfysh
mattfysh / agent.js
Last active August 10, 2021 23:42
Streaming WARC (using HTTPS lib)
const https = require('https')
const { PassThrough } = require('stream')
class WarcAgent extends https.Agent {
createConnection(...args) {
const socket = super.createConnection(...args)
const request = new PassThrough()
const response = new PassThrough()
// request stream via monkey-patching
const origWrite = socket.write
@mattfysh
mattfysh / Grid.svelte
Created September 10, 2021 11:45
CSS Responsive Grid with drag-and-drop items
<script>
import { flip } from 'svelte/animate'
import { dndzone, TRIGGERS } from 'svelte-dnd-action'
import { zip } from 'lodash'
export let ids
export let getItem
// distribute items over column count
let colCount = 4
@mattfysh
mattfysh / redis.js
Created October 25, 2021 05:12
Memolock JS
import Redis from 'ioredis'
const {
HOST: host,
PORT: port,
} = process.env
const redis = new Redis({ host, port })
const subscribe = async (key, notifKey) => {