Skip to content

Instantly share code, notes, and snippets.

View pejalo's full-sized avatar

pejalo

  • Pennsylvania
View GitHub Profile
@pejalo
pejalo / LoadingThreeDots.svelte
Created August 10, 2023 23:07
Simple loading component showing " ..", ". .", ".. ", repeated every second
<script>
// Note: This is a waste of JavaScipt resources, and will not update nicely
// if you are running heavy computations. Better to use an SVG or CSS.
import { onMount } from "svelte"
const fullString = "..."
let currentString = ""
onMount(() => {
@pejalo
pejalo / test.html
Created August 10, 2023 03:12
mocha tests in browser
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My Tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">
<link rel="stylesheet" href="node_modules/mocha/mocha.css" />
<script type="module" src="node_modules/mocha/mocha.js"></script>
<script type="module">
@pejalo
pejalo / eslint.config.js
Created July 9, 2023 11:10
eslint for svelte in flat configuration format
// this file uses eslint's new "flat configuration" format:
// https://eslint.org/docs/latest/use/configure/configuration-files-new
// as of now, there are not many resources online on how to use it.
import js from "@eslint/js"
import globals from 'globals'
import sveltePlugin from 'eslint-plugin-svelte'
import svelteParser from 'svelte-eslint-parser'
import { js as myJsRules, svelte as mySvelteRules } from "./my-eslint-rules.js"
@pejalo
pejalo / google-sheets-subscribe-logger.js
Created July 6, 2023 07:05
Add email address to Google Sheet and log to Cloud Logger
const GoogleSheets = require('@googleapis/sheets');
const GoogleLogging = require('@google-cloud/logging');
// both google services below are authenticated via "Application Default Credentials" (ADC)
// https://googleapis.dev/nodejs/googleapis/latest/sheets/index.html#service-account-credentials
// this will automatically read contents of service account key json file
// as specified at path by environment variable GOOGLE_APPLICATION_CREDENTIALS.
// it would also be possible to specify path programmatically.
// steps to enable service account on google cloud:
@pejalo
pejalo / sendy-subscribe.js
Created July 5, 2023 03:55
Submit nodejs request to Sendy to subscribe email address
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
module.exports = {
subscribe: async (emailAddress) => {
const {
SENDY_API_KEY: apiKey,
SENDY_LIST_ID: listId,
SENDY_SUBSCRIBE_URL: url,
} = process.env;
const body = {
@pejalo
pejalo / TableViewDataSource.swift
Last active April 18, 2018 17:33
Attempt to define UITableViews more declaratively
//
// TableViewDataSource.swift
//
import UIKit
//////////////////////////////
// Project code
//////////////////////////////
@pejalo
pejalo / UIStackView+Alignment.swift
Created April 12, 2018 17:19
Extension for UIStackView to align arranged subviews to left or right
import UIKit
extension UIStackView {
/// [Source](https://www.iamsim.me/uistackview-left-align-without-stretching/)
public func alignArrangedSubviewsToLeft() {
increaseArrangedSubviewsContentHuggingPriority()
let stretchingView = getStretchingViewWithLowContentHuggingPriority()
@pejalo
pejalo / MemoryUsage.swift
Created February 23, 2018 19:06
Swift 4 iOS app memory usage
/// If an error occurs while getting the amount of memory used, the first returned value in the tuple will be 0.
func getMemoryUsedAndDeviceTotalInMegabytes() -> (Float, Float) {
// https://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget/19692719#19692719
// https://stackoverflow.com/questions/27556807/swift-pointer-problems-with-mach-task-basic-info/27559770#27559770
var used_megabytes: Float = 0
let total_bytes = Float(ProcessInfo.processInfo.physicalMemory)
@pejalo
pejalo / post_essentials.js
Created June 1, 2017 07:39
Firebase function for dynamic routing via redirect (essentials)
const admin = require('firebase-admin');
function buildHtmlWithPost (post) {
const string = '<!DOCTYPE html><head>' \
'<title>' + post.title + ' | Example Website</title>' \
'<meta property="og:title" content="' + post.title + '">' \
'<meta property="twitter:title" content="' + post.title + '">' \
'<link rel="icon" href="https://example.com/favicon.png">' \
'</head><body>' \
'<script>window.location="https://example.com/?post=' + post.id + '";</script>' \
@pejalo
pejalo / post.js
Last active November 13, 2022 09:47
Firebase function for dynamic routing via redirect
const admin = require('firebase-admin');
function buildHtmlWithPost (post) {
const title = post.title + ' | Example Website';
var head = {
title: title,
meta: [
// This may not be a valid combination of tags for the services you need to support;