Skip to content

Instantly share code, notes, and snippets.

Avatar

pejalo

View GitHub Profile
@pejalo
pejalo / TableViewDataSource.swift
Last active Apr 18, 2018
Attempt to define UITableViews more declaratively
View TableViewDataSource.swift
//
// TableViewDataSource.swift
//
import UIKit
//////////////////////////////
// Project code
//////////////////////////////
@pejalo
pejalo / UIStackView+Alignment.swift
Created Apr 12, 2018
Extension for UIStackView to align arranged subviews to left or right
View UIStackView+Alignment.swift
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 Feb 23, 2018
Swift 4 iOS app memory usage
View MemoryUsage.swift
/// 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 Jun 1, 2017
Firebase function for dynamic routing via redirect (essentials)
View post_essentials.js
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 Nov 24, 2019
Firebase function for dynamic routing via redirect
View post.js
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;
@pejalo
pejalo / testing.js
Last active Apr 7, 2020
Setup for testing HTTP-triggered Firebase Functions locally
View testing.js
const functions = require('firebase-functions'); // To stub config()
const admin = require('firebase-admin'); // To get credential cert for initializeApp
const firebase = require('firebase'); // To sign in test user and test database writes
const assert = require('chai').assert;
const sinon = require('sinon');
// https://firebase.google.com/docs/functions/unit-testing
// The functions make use of 'firebase-admin', whereas client-side code uses 'firebase'.
// We initialze 'firebase' here to mock client-side code.
You can’t perform that action at this time.