Skip to content

Instantly share code, notes, and snippets.

@danielflippance
danielflippance / list-group-horizontal.css
Created July 7, 2014 23:31
Bootstrap list-group-horizontal
.list-group-horizontal .list-group-item {
display: inline-block;
}
.list-group-horizontal .list-group-item {
margin-bottom: 0;
margin-left:-4px;
margin-right: 0;
}
.list-group-horizontal .list-group-item:first-child {
border-top-right-radius:0;
@aj0strow
aj0strow / self-closing-jsx-tags.js
Created November 5, 2015 22:28
Codemod script to prefer self-closing JSX tags
// jscodeshift -t self-closing-jsx-tags.js ./src
module.exports = function(file, api) {
let j = api.jscodeshift
let root = j(file.source)
root.find(j.JSXElement)
.filter(function (path) {
return !path.value.children.length
})
@ebidel
ebidel / sw_caching_size.js
Last active November 16, 2022 11:31
Print service worker cache sizes and overall bytes cached.
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*/
// Prints the bytes cached by service worker. Breaks out each cache
// overall in-memory bytes used by the Cache Storage API for the site.
async function getCacheStoragesAssetTotalSize() {
// Note: opaque (i.e. cross-domain, without CORS) responses in the cache will return a size of 0.
@RubyRubenstahl
RubyRubenstahl / media.model.js
Created February 21, 2018 02:49
Mongoose discriminators in feathers-cli generated service.
// media-model.js - A mongoose model
//
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
module.exports = function (app) {
const mongooseClient = app.get('mongooseClient');
const { Schema } = mongooseClient;
const options = {
discriminatorKey: 'type',
@nestarz
nestarz / fetchNDJSON.js
Last active July 6, 2024 05:02
NDJSON File Streaming using browser Stream API + Loading Progress
const parseJSON = () =>
new TransformStream({
transform(chunk, controller) {
controller.enqueue(JSON.parse(chunk));
}
});
const splitStream = splitOn => {
let buffer = "";
return new TransformStream({
@derindutz
derindutz / use-persistent-swr.ts
Last active January 6, 2023 08:11
useSWR with localforage as a persistent cache
import useSWR from '@zeit/swr';
import localForage from 'localforage';
import { ConfigInterface } from '@zeit/swr/dist/src/types';
import { useState, useEffect } from 'react';
export function usePersistentSWR(key: string, fn?: Function, config?: ConfigInterface) {
let handleSuccess;
if (config !== undefined && config.onSuccess !== undefined) {
const { onSuccess } = config;
handleSuccess = (data: any, key: string, config: ConfigInterface) => {
@kubido
kubido / rollup.config.js
Last active January 16, 2022 18:51
Svelte rollup config for custom html template with hashed bundle filename
import svelte from "rollup-plugin-svelte";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import livereload from "rollup-plugin-livereload";
import { terser } from "rollup-plugin-terser";
import html from "@rollup/plugin-html";
const production = !process.env.ROLLUP_WATCH;
const version = String(