Skip to content

Instantly share code, notes, and snippets.

Inian inian

Block or report user

Report or block inian

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@inian
inian / split.sh
Created Jun 27, 2019
Convert image to Y, Cb, Cr components
View split.sh
convert image.png -colorspace YUV -sampling-factor 4:2:2 -separate \
\( -clone 0 \) \
\( -clone 1 -fill black -colorize 100% \) \
\( -clone 1 -negate \) \
\( -clone 1 \) \
image_b_temp.png
convert image_b_temp-4.png image_b_temp-5.png image_b_temp-6.png -channel RGB -combine image_b.png
convert image.png -colorspace YUV -sampling-factor 4:2:2 -separate \
View async-decoding.html
<html>
<body>
<div class="jank-detector">
Random numbers, to highlight jank:
<span class="rand"></span>
</div>
<script>
const rand = document.querySelector(".rand");
function randFrame() {
rand.textContent = Math.random();
View image-decode-promise.js
const img = new Image();
img.src = "cat.png";
img.decode().then(() => {
// image fully decoded and can be safely rendered on the screen
const orig = document.getElementById("orig");
orig.parentElement.replaceChild(img, orig);
});
@inian
inian / network-aware-sw.js
Last active Jun 11, 2019
Network aware asset optimization
View network-aware-sw.js
function modifyURL(url) {
// ect can be 'slow-2g', '2g', '3g', or '4g'.
const connectionType = navigator.connection.effectiveType;
if (connectionType === "slow-2g" || connectionType === "2g") {
return url + "?opt=aggressive";
} else if (connectionType === "4g") {
return url + "?opt=mild";
} else {
return url + "?opt=default";
}
@inian
inian / hapi.js
Last active Nov 4, 2017
Node Frameworks using http2
View hapi.js
var fs = require('fs');
var Hapi = require('hapi');
var http2 = require('http2');
var options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
};
var server = new Hapi.Server();
@inian
inian / http2-compatibility-api.js
Last active Nov 4, 2017
Creating a zero-dependency Node.js static file server
View http2-compatibility-api.js
const http2 = require('http2');
const fs = require('fs');
const options = {
key: fs.readFileSync('./selfsigned.key'),
cert: fs.readFileSync('./selfsigned.crt'),
allowHTTP1: true
}
const server = http2.createSecureServer(options, (req, res) => {
@inian
inian / unregister.js
Last active Jun 2, 2018
Unregister Dexecure Service Worker registrations
View unregister.js
try {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
registrations.forEach(function(registration) {
if (registration.active && registration.active.scriptURL.includes("dexecure")) {
console.log('removing registration', registration);
registration.unregister();
}
})
})
} catch (e) {
@inian
inian / brotli-sw.js
Last active Jan 23, 2019
Enabling Brotli on CDNs which don't support it yet
View brotli-sw.js
// MIT License
// Copyright (c) 2016 Dexecure
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@inian
inian / swapon.sh
Created Jan 7, 2016
enable swap on ubuntu 14.04
View swapon.sh
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
@inian
inian / download.sh
Last active Oct 8, 2018
Download webpage using wget
View download.sh
wget -E -H -k -K -p -t 2 -T 30 --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" -e robots=off http://example.com
You can’t perform that action at this time.