Skip to content

Instantly share code, notes, and snippets.

View joshxyzhimself's full-sized avatar

joshxyzhimself joshxyzhimself

  • Philippines
View GitHub Profile
@joshxyzhimself
joshxyzhimself / haversine.sql
Created April 11, 2020 13:27 — forked from carlzulauf/haversine.sql
PostgreSQL function for haversine distance calculation, in miles
-- Haversine Formula based geodistance in miles (constant is diameter of Earth in miles)
-- Based on a similar PostgreSQL function found here: https://gist.github.com/831833
-- Updated to use distance formulas found here: http://www.codecodex.com/wiki/Calculate_distance_between_two_points_on_a_globe
CREATE OR REPLACE FUNCTION public.geodistance(alat double precision, alng double precision, blat double precision, blng double precision)
RETURNS double precision AS
$BODY$
SELECT asin(
sqrt(
sin(radians($3-$1)/2)^2 +
sin(radians($4-$2)/2)^2 *
@joshxyzhimself
joshxyzhimself / README.md
Created June 2, 2020 11:41 — forked from ilyazub/puppeteer-reuse-cookie-in-http-request-from-node.js
Reuse `puppeteer` cookies in `tough-cookie` and `got`

Reuse puppeteer cookies in tough-cookie and got

This way we can send HTTP requests from the Node.js instead of UI interactions.

Set puppeteer cookies to tough-cookie's CookieJar

const cookies = await page.cookies()
cookies.forEach(
  async cookie => {
 await setCookie(
@joshxyzhimself
joshxyzhimself / ssh-tunnel@.service
Created June 26, 2020 04:48 — forked from guettli/ssh-tunnel@.service
Reliable persistent SSH-Tunnel via systemd (not autossh)
# Reliable persistent SSH-Tunnel via systemd (not autossh)
# https://gist.github.com/guettli/31242c61f00e365bbf5ed08d09cdc006#file-ssh-tunnel-service
[Unit]
Description=Tunnel for %i
After=network.target
[Service]
User=tunnel
ExecStart=/usr/bin/ssh -o "ExitOnForwardFailure yes" -o "ServerAliveInterval 60" -N tunnel@%i
@joshxyzhimself
joshxyzhimself / download-pdf.js
Created July 29, 2020 04:24 — forked from devloco/download-pdf.js
Download a PDF via POST with Fetch API
let fnGetFileNameFromContentDispostionHeader = function (header) {
let contentDispostion = header.split(';');
const fileNameToken = `filename*=UTF-8''`;
let fileName = 'downloaded.pdf';
for (let thisValue of contentDispostion) {
if (thisValue.trim().indexOf(fileNameToken) === 0) {
fileName = decodeURIComponent(thisValue.trim().replace(fileNameToken, ''));
break;
}
@joshxyzhimself
joshxyzhimself / haproxy-config-2-0.cfg
Created September 4, 2020 16:28 — forked from haproxytechblog/haproxy-config-2-0.cfg
HAProxy 2.0 configuration
#
# This is the ultimate HAProxy 2.0 "Getting Started" config
# It demonstrates many of the features available which are now available
# While you may not need all of these things, this can serve
# as a reference for your own configurations.
#
# Have questions? Check out our community Slack:
# https://slack.haproxy.org/
#
@joshxyzhimself
joshxyzhimself / JSON-intArray-converter.js
Created February 26, 2021 23:17 — forked from tomfa/JSON-intArray-converter.js
JSON to 8-bit-integer parsing (and visa versa)
// JSON to Uint8Array parsing and visa versa
// (Intended Bluetooth communication on Cordova)
var JsonToArray = function(json)
{
var str = JSON.stringify(json, null, 0);
var ret = new Uint8Array(str.length);
for (var i = 0; i < str.length; i++) {
ret[i] = str.charCodeAt(i);
}
@joshxyzhimself
joshxyzhimself / Node.JS 8.9.4 - V8 6.1.534.50
Created April 9, 2021 08:33 — forked from ColonelBundy/Node.JS 8.9.4 - V8 6.1.534.50
Promise vs Callback vs Async/await benchmark 2018
Doxbee sequential
benchmarking ./doxbee-sequential/async-bluebird.js
{"time":428,"mem":60.38671875,"errors":0,"lastErr":null}
benchmarking ./doxbee-sequential/async-es2017-native.js
{"time":591,"mem":98.82421875,"errors":0,"lastErr":null}
benchmarking ./doxbee-sequential/async-es2017-util.promisify.js
{"time":479,"mem":69.7734375,"errors":0,"lastErr":null}
benchmarking ./doxbee-sequential/callbacks-baseline.js
{"time":149,"mem":29.99609375,"errors":0,"lastErr":null}

Unofficial Bash Strict Mode

Sometimes a programming language has a "strict mode" to restrict unsafe constructs. E.g., Perl has use strict, Javascript has "use strict", and Visual Basic has Option Strict. But what about bash? Well, bash doesn't have a strict mode as such, but it does have an unofficial strict mode:

set -euo pipefail

set -e

@joshxyzhimself
joshxyzhimself / https-during-dev.macos.sh
Created February 14, 2022 05:39 — forked from disintegrator/https-during-dev.macos.sh
Use Caddy, mkcert and dnsmasq to expose your development server over HTTPS
brew install caddy mkcert nss dnsmasq
mkcert -install
mkcert '*.app.test' '*.cdn.test'
# rename the certs and move them under /usr/local/etc/caddy/certs
cat <<EOF > /usr/local/etc/caddy/Caddyfile
*.app.test:443, *.cdn.test:443 {
@joshxyzhimself
joshxyzhimself / offline-gmaven-stable.zip - how to use Android Studio with downloads of offline Android Gradle plugin and Google Maven repository dependencies.md
Created July 14, 2022 06:28
offline-gmaven-stable.zip - how to use Android Studio with downloads of offline Android Gradle plugin and Google Maven repository dependencies.

Use the Android Gradle Plugin offline

This document describes how to use Android Studio with downloads of offline Android Gradle plugin and Google Maven repository dependencies.

Download and unzip offline components

If you haven’t already done so, download the offline components from the official Android Studio website: https://d.android.com/r/studio-offline/downloads .