Skip to content

Instantly share code, notes, and snippets.

View elyobo's full-sized avatar

Liam O'Boyle elyobo

View GitHub Profile
@wojtekmaj
wojtekmaj / jest-to-vitest.sh
Last active April 26, 2024 14:08
Automatically migrate Jest project to Vitest
#!/bin/bash
# Ensure we're working on the latest version of the main branch
git switch main
git fetch
git pull
# Create a new branch
git switch -c vitest

Creating standalone ESM-based Node.js scripts on Unix and Windows

Approach:

  1. The file starts with shell code.
  2. That code uses Node.js to execute the file in ESM mode, after it removes the initial non-JavaScript lines.
    • Node.js does not currently have CLI flags for achieving what we do in this step. Therefore, we have to pipe to the node executable.

When editing this file, we want to use the JavaScript mode of our IDE or editor. Therefore, we try to “hide” the shell code from JavaScript as much as possible.

@developit
developit / *babel-plugin-dynamic-import-polyfill.md
Created November 12, 2019 19:57
babel-plugin-dynamic-import-polyfill
@rob-murray
rob-murray / siege_examples.sh
Last active April 1, 2024 03:48
Siege examples
# Basic example
siege -t60s -c20 -d10 'http://robertomurray.co.uk/'
# Basic auth;
auth=$(echo -n 'username:password' | openssl base64)
siege -t60s -c20 -d10 --header="Authorization:Basic $auth" 'https://staging.a-hostname.co.uk/'
@dherman
dherman / geomean.js
Last active January 9, 2020 23:28
calculating the geometric mean in normal JS and asm.js
// Calculating the geometric mean in log space avoids overflow when
// working with anything more than very small data sets.
//
// The formula can be calculated with simple algebraic identities:
//
// n√(Prod^n x_i)
// = { e^ln(x) = x }
// n√(Prod^n e^ln(x_i))
// = { e^a x e^b = e^(a+b) }
// n√(e^(Sum^n ln(x_i)))
@pmeenan
pmeenan / user-timing-rum.js
Last active January 18, 2024 23:46
Support routine for adding W3C user timing events to a site. Includes some basic polyfill support for browsers that don't support user timing or navigation timing (though the start time for non-navigation timing support could be improved with IE < 9 to use IE's custom start event).
// Support routines for automatically reporting user timing for common analytics platforms
// Currently supports Google Analytics, Boomerang and SOASTA mPulse
// In the case of boomerang, you will need to map the event names you want reported
// to timer names (for mPulse these need to be custom0, custom1, etc) using a global variable:
// rumMapping = {'aft': 'custom0'};
(function() {
var wtt = function(n, t, b) {
t = Math.round(t);
if (t >= 0 && t < 3600000) {
// Google Analytics
@Sitebase
Sitebase / gist:4510386
Created January 11, 2013 12:43
Phing list fileset
<fileset id="src.php.custom" dir="${base.dir}src/application/">
<include name="controllers/**/*.php" />
<include name="core/**/*.php" />
<include name="models/**/*.php" />
<include name="modules/**/*.php" />
<include name="helpers/**/*.php" />
<exclude name="**/libraries/**/*.php" />
</fileset>
<target name="fileset-list">
@fennb
fennb / gist:1283573
Created October 13, 2011 06:35
nginx microcaching config example
# Set cache dir
proxy_cache_path /var/cache/nginx levels=1:2
keys_zone=microcache:5m max_size=1000m;
# Virtualhost/server configuration
server {
listen 80;
server_name yourhost.domain.com;
# Define cached location (may not be whole site)