Skip to content

Instantly share code, notes, and snippets.

View jasonbyrne's full-sized avatar

Jason Byrne jasonbyrne

View GitHub Profile
@jasonbyrne
jasonbyrne / counties.py
Created March 29, 2024 17:14
Python array of all US counties
class County:
def __init__(self, state_code: str, county_name: str):
self.state_code = state_code
self.county_name = county_name
counties = [
County("AL","Autauga"),
County("AL","Baldwin"),
County("AL","Barbour"),
@jasonbyrne
jasonbyrne / blackjack.py
Last active March 9, 2024 13:17
Black Jack Python Game - First time writing Python
import random
# List of available cards and values
cards = {
"2": 2,
"3": 3,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
@jasonbyrne
jasonbyrne / extracted-email-message.interface.ts
Created January 20, 2023 21:33
Email message as extracted by postal-mime from Cloudflare Email Router's raw property
export interface EmailAttachment {
filename: string;
mimeType: string;
disposition: string;
related: boolean;
contentId: string;
content: unknown;
}
export interface EmailAddress {
@jasonbyrne
jasonbyrne / index.ts
Created January 20, 2023 19:23
Cloudflare Workers Email Routing POC
const PostalMime = require('postal-mime');
export interface EmailMessage {
readonly from: string;
readonly to: string;
readonly headers: Headers;
readonly raw: ReadableStream;
readonly rawSize: number;
setReject(reason: String): void;
forward(rcptTo: string, headers?: Headers): Promise<void>;
@jasonbyrne
jasonbyrne / time-ago.ts
Created January 17, 2023 01:36
Simple ago function to calculate, with a concise string, how old a post is
const DAY_SECONDS = 86400;
const WEEK_SECONDS = 604800;
const YEAR_SECONDS = WEEK_SECONDS * 52;
export function timeAgo(date: Date) {
const epoch = Math.round(date.getTime() / 1000);
const now = Math.round(Date.now() / 1000);
const seconds = now - epoch;
const minutes = Math.round(seconds / 60);
const hours = Math.round(seconds / 3600);
const values = ['foo', 'bar'] as const;
type MyValues = typeof values[number];
function isOneOfMyValues(elem: unknown): elem is MyValues {
const opts: string[] = [...values];
return opts.includes(String(elem));
}
function lengthOfMyThing(x: MyValues | null) {
if (isOneOfMyValues(x)) {
@jasonbyrne
jasonbyrne / color-names.js
Created May 17, 2022 11:41
Standard HTML Color Names Array
export const COLOR_NAMES = [
'aliceblue',
'antiquewhite',
'aqua',
'aquamarine',
'azure',
'beige',
'bisque',
'black',
'blanchedalmond',
@jasonbyrne
jasonbyrne / generate-svg.ts
Created May 17, 2022 11:39
Generate Placeholder SVG with Cloudflare Workers
// Credit:: https://github.com/cloudfour/simple-svg-placeholder
type SvgOptions = {
width: number
height: number
text: string
fontFamily: string
fontWeight: string
bgColor: string
textColor: string
@jasonbyrne
jasonbyrne / fetch-thumbnail.ts
Created May 17, 2022 11:37
Fetch Thumbnail, resize and serve with Cloudflare Worker
import { IncomingRequest } from '../incoming-request'
const buckets: { [key: string]: string } = {
'bucket-name': 'https://bucket-url/',
}
interface RequestInitWithCf extends RequestInit {
cf: RequestInitCfProperties & {
image: BasicImageTransformations & {
quality?: number | undefined
@jasonbyrne
jasonbyrne / hello-world.ts
Created May 17, 2022 11:32
CloudFlare Workers Router in TypeScript v2
export function helloWorld(): Response {
return new Response('Hello World', {
status: 200,
})
}