Skip to content

Instantly share code, notes, and snippets.

View cvan's full-sized avatar
🚌
🌊

Christopher Van Wiemeersch cvan

🚌
🌊
View GitHub Profile
@willywongi
willywongi / 1-echo.js
Last active July 8, 2025 05:06
Load a Worker from a different domain (CORS + tricks)
/*
You want to use webworkers, but you host all of your js files on a different domain than where
your app lives (es. app.example.com and js.example.com). Given that the static file served from
js.example.com are CORS ready (in that the response header includes Accept-origin: *), I thought
I could load a Worker from other domains. I was almost wrong, but at last I found a solution:
XHRing the worker source and create an inline worker. This is tested only on Firefox (latest).
*/
// This is an example webworker that is on js.example.com. It just echoes messages it receive.
self.onmessage = function(e) {
self.postMessage(e.data);
@mikeal
mikeal / gist:6137274
Last active December 20, 2015 13:18
NodeBase chat on Search
@PaulKinlan
PaulKinlan / criticalcss-bookmarklet-devtool-snippet.js
Last active March 12, 2025 01:22
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@Melindrea
Melindrea / menus.html
Last active November 30, 2016 15:55
Patterns to use aria roles, both HTML and a sketch for the CSS
<!-- navigational menubar (with drop down submenu, without works as well) -->
<nav aria-label="main" role="navigation"><!-- role explicit for older browsers, using aria-label to differentiate from other navs -->
<ul role="menubar" aria-activedescendant="home-menuitem">
<li role="presentation">
<a href="#" role="menuitem" aria-selected="true" id="home-menuitem">Home</a></li>
<li role="presentation">
<a href="#" role="menuitem" aria-selected="false" id="link-menuitem">Link</a>
</li>
<li role="presentation">
<!-- using button to be triggered on-click -->
var sanitize = (function(doc){
var slice = Array.prototype.slice,
range = doc.createRange(),
frag = doc.createDocumentFragment(),
wrap = frag.appendChild(doc.createElement('div'));
function cleanNode(node, unwrap){
var parent = node.parentNode;
if (unwrap){
@plentz
plentz / nginx.conf
Last active August 25, 2025 02:13
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@luozhihua
luozhihua / auto-restart-nodejs-process
Last active August 7, 2022 06:21
Auto restart nodejs process when program exit
var child_process = require('child_process');
start();
function start(nodefile) {
if (typeof start !== 'string') {
console.log('Has none file. like this: start("app.js")');
}
console.log('Master process is running.');
@ungoldman
ungoldman / dokku_setup.md
Last active November 28, 2023 12:35
Deploy your own PaaS: Setting up Dokku with DigitalOcean and Namecheap

Deploy your own PaaS!

Setting up Dokku with DigitalOcean and Namecheap

..or how I made my own heroku in a few hours for $3.98.


This write-up is several years out of date! You probably shouldn't use it.

@sstur
sstur / dom-to-json.js
Last active October 8, 2023 04:17
Stringify DOM nodes using JSON (and revive again)
function toJSON(node) {
let propFix = { for: 'htmlFor', class: 'className' };
let specialGetters = {
style: (node) => node.style.cssText,
};
let attrDefaultValues = { style: '' };
let obj = {
nodeType: node.nodeType,
};
if (node.tagName) {
var dombind = (function() {
function makeSmart(obj) {
obj.__bound__ = {};
}
function isSmart(obj) {
return '__bound__' in obj;
}