Skip to content

Instantly share code, notes, and snippets.

View dimorphic's full-sized avatar
🤖
*void 0*

Sabin Tudor dimorphic

🤖
*void 0*
View GitHub Profile
@kidGodzilla
kidGodzilla / openai-chat-completion.js
Last active April 5, 2024 21:15
OpenAI Chat Completion Example
const { Configuration, OpenAIApi } = require('openai');
let openai;
const instructions = ``;
if (process.env.OPEN_AI_API_KEY) {
const configuration = new Configuration({ apiKey: process.env.OPEN_AI_API_KEY });
openai = new OpenAIApi(configuration);
}
@Ocramius
Ocramius / git-flow_vs_github-flow.md
Created October 7, 2022 08:38
Git-flow vs GitHub-flow

Git-flow vs GitHub-flow

What we want

A list of requirements:

  • stakeholders expect a list of provided features, every few days, in a human-friendly report
  • every change must have been reviewed, before being deployed
  • every change must have passed our automated checks, before being deployed
  • every change must have been verified by QA staff, before being deployed
@kidGodzilla
kidGodzilla / country_code_to_name.js
Created June 26, 2022 16:16
Country code to name
function countryCodeToName(code) {
const data = {
"AD": "Andorra",
"AE": "United Arab Emirates",
"AF": "Afghanistan",
"AG": "Antigua and Barbuda",
"AI": "Anguilla",
"AL": "Albania",
"AM": "Armenia",
"AO": "Angola",
@kidGodzilla
kidGodzilla / region_code_lookup.js
Last active April 5, 2024 21:16
Region Code Lookup (Javascript)
// Raw data from: https://github.com/country-regions/country-region-data/blob/master/data.json
const data = JSON.parse('[{"countryName":"Afghanistan","countryShortCode":"AF","regions":[{"name":"Badakhshan","shortCode":"BDS"},{"name":"Badghis","shortCode":"BDG"},{"name":"Baghlan","shortCode":"BGL"},{"name":"Balkh","shortCode":"BAL"},{"name":"Bamyan","shortCode":"BAM"},{"name":"Daykundi","shortCode":"DAY"},{"name":"Farah","shortCode":"FRA"},{"name":"Faryab","shortCode":"FYB"},{"name":"Ghazni","shortCode":"GHA"},{"name":"Ghor","shortCode":"GHO"},{"name":"Helmand","shortCode":"HEL"},{"name":"Herat","shortCode":"HER"},{"name":"Jowzjan","shortCode":"JOW"},{"name":"Kabul","shortCode":"KAB"},{"name":"Kandahar","shortCode":"KAN"},{"name":"Kapisa","shortCode":"KAP"},{"name":"Khost","shortCode":"KHO"},{"name":"Kunar","shortCode":"KNR"},{"name":"Kunduz","shortCode":"KDZ"},{"name":"Laghman","shortCode":"LAG"},{"name":"Logar","shortCode":"LOW"},{"name":"Maidan Wardak","shortCode":"WAR"},{"name":"Nangarhar","shortCode":"NAN
@kidGodzilla
kidGodzilla / browser-icon.js
Created May 29, 2022 17:34
Infer Browser by input string & return an icon
/***
* Given a slightly messy set of input strings, attempt to match a well-known browser name, and return an icon
*
* Examples:
* inferBrowserIcon('safari') // exact match
* inferBrowserIcon('Safari Mobile 15.4') // matches "safari" from input string
* inferBrowserIcon('Firefox 99', 128) // pick a specific size (from sizes)
* inferBrowserIcon('unknownbrowser') // fallback if no match
* inferBrowserIcon(null, 128, 'brave') // You know the browser-logos repo key
*/
@kidGodzilla
kidGodzilla / geoip.js
Created February 22, 2022 20:08
Geo IP node / express
const requestIp = require('request-ip');
function getIp (req) {
let ip = null;
try {
//ip = (req.headers['x-forwarded-for'] || '').split(',').pop() ||
// req.connection.remoteAddress ||
// req.socket.remoteAddress ||
// req.connection.socket.remoteAddress;
@jfet97
jfet97 / DFS.js
Last active August 26, 2023 10:02
Simple Depth First Search in JavaScript
function isObject(entity) {
return typeof entity === "object" && entity !== null;
}
function getAdjacentNodes(obj) {
return (
Object.entries(obj)
.filter(([, v]) => isObject(v))
)
}
@SuwakoMmh
SuwakoMmh / Gitbridge.md
Last active May 14, 2023 14:30
Using the same SSH key for multiple Github (& co) accounts

Using the same SSH key for multiple Github (& co) accounts

The most known hack is to edit ~/.ssh/config and use a different hostname in place of github.com for each account. (ref this gist)

However, one might still want to use github.com as a hostname for various reasons. Hence this hack idea I had.

1. Creating a bridge user

This may vary depending on the distribution, but for ubuntu or any given useradd :

# useradd -r -m -d /opt/git git
@kidGodzilla
kidGodzilla / dokku_on_digital_ocean.md
Created October 25, 2020 06:43 — forked from henrik/dokku_on_digital_ocean.md
Notes from running Dokku on Digital Ocean.

My notes for Dokku on Digital Ocean.

These may be a bit outdated: Since I originally wrote them, I've reinstalled on a newer Dokku and may not have updated every section below.

Commands

Install dokku-cli (gem install dokku-cli) for a more Heroku-like CLI experience (dokku config:set FOO=bar).

# List/run commands when not on Dokku server (assuming a "henroku" ~/.ssh/config alias)

ssh henroku dokku

@benhatsor
benhatsor / IDFromTime.js
Last active February 10, 2024 15:47
Generate a unique ID based on the current time. Note: If you need a truly unique ID, use something like the JS Crypto API instead.
// Both numbers and letters
function mixedID() {
var now = new Date();
timestamp = now.getFullYear().toString();
timestamp += (now.getMonth < 9 ? '0' : '') + now.getMonth().toString();
timestamp += ((now.getDate < 10) ? '0' : '') + now.getDate().toString();
timestamp += now.getHours().toString();
timestamp += now.getMinutes().toString();
timestamp += now.getSeconds().toString();