Skip to content

Instantly share code, notes, and snippets.

View ksafranski's full-sized avatar

Kent Safranski ksafranski

View GitHub Profile
@ksafranski
ksafranski / Common-Currency.json
Last active April 22, 2024 15:16
Common Currency Codes in JSON
{
"USD": {
"symbol": "$",
"name": "US Dollar",
"symbol_native": "$",
"decimal_digits": 2,
"rounding": 0,
"code": "USD",
"name_plural": "US dollars"
},
import os
import requests
import json
from pathlib import Path
from openai import OpenAI, openai
from datetime import datetime, timedelta
import asyncio
# Assuming OpenAI Python client is already installed, configured with API key
openai.api_key = os.getenv('OPEN_AI_API_KEY')
@ksafranski
ksafranski / expecting.md
Last active November 11, 2023 23:00
Basic principles of using tcl-expect scripts

Intro

TCL-Expect scripts are an amazingly easy way to script out laborious tasks in the shell when you need to be interactive with the console. Think of them as a "macro" or way to programmaticly step through a process you would run by hand. They are similar to shell scripts but utilize the .tcl extension and a different #! call.

Setup Your Script

The first step, similar to writing a bash script, is to tell the script what it's executing under. For expect we use the following:

#!/usr/bin/expect
@ksafranski
ksafranski / get.spec.ts
Created August 18, 2023 19:03
Lodash `get` alternative
describe('get', () => {
it('return undefined on non-existent key', () => {
const res = get({ hello: 'world' }, 'foo');
expect(res).toBeUndefined();
});
it('returns key when nested', () => {
const res = get({ hello: { world: false } }, 'hello.world');
expect(res).toEqual(false);
});
});
@ksafranski
ksafranski / SimpleStore.js
Last active July 2, 2022 15:25
Simple localStorage function with Cookie fallback for older browsers.
/**
* Simple localStorage with Cookie Fallback
* v.1.0.0
*
* USAGE:
* ----------------------------------------
* Set New / Modify:
* store('my_key', 'some_value');
*
* Retrieve:
@ksafranski
ksafranski / deploy.js
Created May 20, 2014 12:47
Deploy to multiple environments on Nodejitsu with the same application
// Nodejitsu multiple environment deploy
//
// Prerequisits:
// Jitsu deploy CLI
//
// Usage:
// Include this file in root of project along with configured
// jitsu_conf.json file
// Run by calling:
// node deploy [ENV]

Using Git

This document is a quick-start dive into using Git for version control, branching, and collaborative work on projects. It is intended to be a primer on core concepts. For more information, see the Git Docs.

Authentication

The best way to use Git + Github (or any Git hosting) is via SSH. To do this you need an SSH Key (Mac/Linux):

ssh-keygen
@ksafranski
ksafranski / Router.js
Last active June 15, 2020 11:59
Simple hash-based router with :params and 404
// Router object
var Router = function () {
var self = this;
// Watch hashchange
window.onhashchange = function () {
self.process();
};
// Run on load
@ksafranski
ksafranski / api.php
Created November 6, 2012 19:31
PHP API Framework
<?php
// HTACCESS:
// ----------------------------------
// Options +FollowSymLinks
// RewriteEngine On
// RewriteCond %{REQUEST_FILENAME} !-f
// RewriteCond %{REQUEST_FILENAME} !-d
// RewriteRule ^ api.php [QSA,L]
/**
* Function for converting arbitrarily nested arrays into a single, flat array
* @param {Array} arr
* @returns {Array}
*/
function flatDeep (arr) {
if (!Array.isArray(arr)) throw new Error('Expected type `Array`')
return arr.reduce((acc, el) => acc.concat(Array.isArray(el) ? flatDeep(el) : el), [])
}