Skip to content

Instantly share code, notes, and snippets.

View gamedevsam's full-sized avatar

Samuel Batista gamedevsam

View GitHub Profile
@gamedevsam
gamedevsam / deploy_dokku.mjs
Last active October 23, 2023 15:45
Script to deploy docker file to dokku (requires node 18 or greater + node-ssh and xid-js npm packages)
import 'dotenv/config';
import { NodeSSH } from 'node-ssh';
import { mkdir } from 'node:fs/promises';
import { parseArgs } from 'node:util';
import { next as generate_xid } from 'xid-js';
import { printDuration, spawnPromise } from './utilities/spawn_promise.mjs';
const { values: argv } = parseArgs({
options: {
// (required) name of app to deploy, defaults to app-dev
@gamedevsam
gamedevsam / gist:30ceafa0a81ef705e4b8b980643091ef
Created October 22, 2023 18:02
Deploy node@18 in Docker with pnpm
#
# Setup
#
# Use FROM node:lts-alpine for minimum file size
# Use FROM node:lts-slim for maximum compatibility
# More info:
# https://snyk.io/blog/choosing-the-best-node-js-docker-image/
# https://www.specfy.io/blog/1-efficient-dockerfile-nodejs-in-7-steps
#
# To print commands and debug building dockerfile use:
@gamedevsam
gamedevsam / README.md
Last active February 28, 2022 18:30
Deep object comparison benchmark

Requires hyperfine to run: https://github.com/sharkdp/hyperfine

Run it like so: hyperfine 'node dequal.mjs' 'node md5.mjs' 'node sha1.mjs'

Results:

Summary
  'node dequal.mjs' ran
    1.16 ± 0.20 times faster than 'node md5.mjs'
 1.17 ± 0.21 times faster than 'node sha1.mjs'
@gamedevsam
gamedevsam / objectUtilities.ts
Last active February 25, 2022 01:35
Simple deep equals implementation
// Largely based on the dequal package by lukeed, minus Date and RegExp capabilities: https://www.npmjs.com/package/dequal
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function deepEquals(foo: any, bar: any): boolean {
let ctor, len: number;
if (foo === bar) {
return true;
}
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
if (ctor === Array) {
@gamedevsam
gamedevsam / FunctionalVsOop.js
Last active December 31, 2021 18:59
A contrived example showing how a problem can be solved with classes or with functions in JS
/**
* This example compares how one might go about converting an array to a string using classes or functions:
*/
const EXAMPLE_DATA = ['This', 'is', 'a', 'contrived', 'example'];
/**
* In this first example we use a class to hold our array and a method to transform it into a string:
*/
class ArrayToStringClass {
constructor(array) {

So, if you want to be a better leader, take a page out Sundar Pichai's playbook and ask yourself:

"What ties did I break this week?"

Campbell wasn't speaking about breaking ties as in cutting off relationships. Rather, he was teaching Pichai that he needed to break stalemates.

Then, remember to:

  • Prioritize those you want to please
  • Pursue progress, not perfection
@gamedevsam
gamedevsam / Isaac_the_bartender.txt
Last active October 30, 2020 04:14
A conversation with a bartender in Hong Kong
...
JC:
What does China fear?
Isaac:
China is the last sovereign government in the world. Authoritarian but willing -- unlike U.N.-governed countries -- to give its people the freedom to do what they want.
JC:
As long as they don't break the law.
@gamedevsam
gamedevsam / blockstack-id.txt
Last active October 30, 2018 18:49
BlockStack ID
Verifying my Blockstack ID is secured with the address 1PpgJoxQiPrKSJeqjqFCEt9zCFJm9nejLr https://explorer.blockstack.org/address/1PpgJoxQiPrKSJeqjqFCEt9zCFJm9nejLr
@gamedevsam
gamedevsam / keybase.md
Created January 12, 2017 21:30
Early adopter of a blockchain identity service, nothing to see here.

Keybase proof

I hereby claim:

  • I am gamedevsam on github.
  • I am sambatista (https://keybase.io/sambatista) on keybase.
  • I have a public key whose fingerprint is F546 0360 418D EDB8 68E4 E932 5EB8 3CE4 C0C7 EB59

To claim this, I am signing this object:

@gamedevsam
gamedevsam / Account.php
Last active February 17, 2016 11:41
Generate PHP Externs with Haxe Macros
<?php
class Account
{
public function __construct($consumer)
{
(...)
}
public function GetAccountList()