Skip to content

Instantly share code, notes, and snippets.

@mattfysh
mattfysh / Grid.svelte
Created Sep 10, 2021
CSS Responsive Grid with drag-and-drop items
View Grid.svelte
<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 / agent.js
Last active Aug 10, 2021
Streaming WARC (using HTTPS lib)
View agent.js
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 / 1-before.js
Last active Aug 10, 2021
Shouty Stream
View 1-before.js
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 / 5reqs.sh
Last active Jul 18, 2021
Luminati Performance
View 5reqs.sh
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 / client.js
Last active Jul 7, 2021
urql + auth-exchange + aws-amplify
View client.js
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
View gist:89aa4dd9163c7f43375368c4dbf97669
import { onMount } from 'svelte';
function noop() { }
function run(fn) {
return fn();
}
function blank_object() {
return Object.create(null);
}
function run_all(fns) {
View .eslintrc.yaml
env:
node: true
es6: true
parserOptions:
ecmaVersion: 2020
sourceType: module
extends:
- airbnb-base
@mattfysh
mattfysh / main.cpp
Created Feb 1, 2020
Runtime symbols
View main.cpp
#include <iostream>
using namespace std;
template<typename T>
T make_symbol(T value, string metadata);
template<typename T>
string get_symbol_for(T value);
View utils.js
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;