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/
#
import { useState, useEffect, useCallback } from 'react';
function useHistory () {
const [pathname, set_pathname] = useState(window.location.pathname);
const push = useCallback((next_pathname) => {
if (pathname !== next_pathname) {
window.history.pushState(null, null, next_pathname);
@joshxyzhimself
joshxyzhimself / arbitrary.js
Last active January 23, 2021 14:07
Arbitrary-precision arithmetic
class AssertionError extends Error {
/**
* @param {String|void} message
*/
constructor (message) {
super(message);
this.name = 'AssertionError
if (Error.captureStackTrace instanceof Function) {
Error.captureStackTrace(this, AssertionError);
@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}
// rendered at http://localhost:8080/account
export const Account = (props) => {
const { user } = props;
return (
<div>
{ user.username }
</div>
);
};