Skip to content

Instantly share code, notes, and snippets.

@Rich-Harris
Rich-Harris / service-workers.md
Last active March 28, 2024 15:08
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@y0ngb1n
y0ngb1n / docker-registry-mirrors.md
Last active March 28, 2024 15:08
国内的 Docker Hub 镜像加速器,由国内教育机构与各大云服务商提供的镜像加速服务 | Dockerized 实践 https://github.com/y0ngb1n/dockerized

Docker Hub 镜像加速器

国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务。

Dockerized 实践 https://github.com/y0ngb1n/dockerized

配置加速地址

Ubuntu 16.04+、Debian 8+、CentOS 7+

@ovzer
ovzer / index.html
Last active March 28, 2024 15:08
Website that closes itself
<!doctype html><html><head><script>
window.onload = function load() {
window.close('','_parent','');
};
</script></head><body></body></html>
@peter-kehl
peter-kehl / rust_const_generics.md
Last active March 28, 2024 15:07
Rust Const Generics

Presentation on Const Generics as of 1.50.0 stable and 1.52.0-nightly

Challenges

  • Beware no, or misleading, documentation
  • Syntax may seem arbitrary:
    • Need ::< turbofish at some places, ordinary < elsewhere.
    • Need {...} curly brackets around some const generic parameter values, not around others.
    • Some error messages feel like going in circles.
@richkuz
richkuz / insert-date-mac-osx.md
Created June 12, 2020 15:35
Insert ISO-8601 formatted date yyyy-mm-dd on Mac OSX using a keyboard shortcut

Recently, I converted to using ISO-8601 formatted dates as much as possible, e.g. 2020-06-12. As a meme, I hope this catches on. Dates written this way are internationally recognizable, no confusion over mm/dd/yy or dd/mm/yy. They are sortable. And, when used consistently, they are easy to search; no worries about case sensitivity, or Jun/June spellings. Don’t take my word for it, though. Randall Munroe agrees. So does GitLab.

Here's how to create a keyboard shortcut to insert the current date formatted as ISO-8601.

  1. Launch Automator, and create a new Service.

  2. This particular service receives no input.

  3. Drag in Run AppleScript to the service.

@mattclements
mattclements / .htaccess
Created August 10, 2012 20:55
Sample HTAccess File
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
ErrorDocument 400 /error_pages/400.php
ErrorDocument 401 /error_pages/401.php
ErrorDocument 403 /error_pages/403.php
ErrorDocument 404 /error_pages/404.php
ErrorDocument 410 /error_pages/410.php
@OrionReed
OrionReed / DOM3D.js
Last active March 28, 2024 15:05
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@Danetag
Danetag / useMyAwesomeHook.specs.tsx
Last active March 28, 2024 15:00
Testing a React hook with a redux store
import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import stateFactory from 'jest/stateFactory';
import configureMockStore from 'redux-mock-store';
import { Provider } from 'react-redux';
import { Store, AnyAction } from 'redux';
import { initialState as initialPaginationState } from '../../store/pagination/reducer';
import { useMyAwesomeHook } from '../useMyAwesomeHook';
@sharryy
sharryy / schema-dump.php
Created March 28, 2024 12:47
A simple laravel command to prune and squash migration using MySQL from Docker container.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
class DockerSchemDumpCommand extends Command
{
@jjsquady
jjsquady / nextjs-deploy.md
Last active March 28, 2024 14:59
Deploying NEXTJS site with nginx + pm2

How to setup next.js app on nginx with letsencrypt

next.js, nginx, reverse-proxy, ssl

1. Install nginx and letsencrypt

$ sudo apt-get update
$ sudo apt-get install nginx letsencrypt

Also enable nginx in ufw