Skip to content

Instantly share code, notes, and snippets.

View cvan's full-sized avatar
🚌
🌊

Christopher Van Wiemeersch cvan

🚌
🌊
View GitHub Profile
@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.');
@plentz
plentz / nginx.conf
Last active May 3, 2025 05:27
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
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){
@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 -->
@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(": ");
@mikeal
mikeal / gist:6137274
Last active December 20, 2015 13:18
NodeBase chat on Search
@willywongi
willywongi / 1-echo.js
Last active January 23, 2024 06:45
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);
@mathiasbynens
mathiasbynens / url-code-points.js
Last active October 27, 2016 14:46
Let’s create a JavaScript-compatible regular expression that matches any URL code point, as per the URL Standard.
// “The URL code points are ASCII alphanumeric, "!", "$", "&", "'", "(", ")",
// "*", "+", ",", "-", ".", "/", ":", ";", "=", "?", "@", "_", "~", and code
// points in the ranges U+00A0 to U+D7FF, U+E000 to U+FDCF, U+FDF0 to U+FFEF,
// U+10000 to U+1FFFD, U+20000 to U+2FFFD, U+30000 to U+3FFFD, U+40000 to
// U+4FFFD, U+50000 to U+5FFFD, U+60000 to U+6FFFD, U+70000 to U+7FFFD, U+80000
// to U+8FFFD, U+90000 to U+9FFFD, U+A0000 to U+AFFFD, U+B0000 to U+BFFFD,
// U+C0000 to U+CFFFD, U+D0000 to U+DFFFD, U+E1000 to U+EFFFD, U+F0000 to
// U+FFFFD, U+100000 to U+10FFFD.”
// — http://url.spec.whatwg.org/#url-code-points
for file in `git diff-tree --no-commit-id --name-only -r HEAD | sort | uniq`
do
if [ ${file: -3} == ".py" ]
then
flake8 --ignore=E121,E123,E124,E125,E126,E127,E128 $file
fi
if [ ${file: -3} == ".js" ]
then
jshint $file
fi
@NV
NV / Readme.md
Last active January 7, 2025 08:28
Prepend the debugger statement to a function as easy as stopBefore('Element.prototype.removeChild'). Works in Chrome DevTools and Safari Inspector, doesn’t work in Firebug‘s and Firefox Developer Tools‘ console (I don’t know why). Works as a standalone script everywhere.

stopBefore.js

2min screencast

Examples

stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')