Skip to content

Instantly share code, notes, and snippets.

@hfossli
hfossli / fastlane-diff.sh
Last active June 29, 2018 14:28
Get time difference between output lines from fastlane
#!/bin/bash
CLEAR='\033[0m'
RED='\033[38;5;160m'
ORANGE='\033[38;5;202m'
YELLOW='\033[38;5;220m'
GREEN='\033[0;32m'
BLUE='\033[0;36m'
GREY='\033[38;5;237m'
@hfossli
hfossli / time-diff-output.sh
Created August 1, 2018 08:44
Get time difference between output line. Supports logs from fastlane as well!
#!/bin/bash
CLEAR='\033[0m'
RED='\033[38;5;160m'
ORANGE='\033[38;5;202m'
YELLOW='\033[38;5;220m'
GREEN='\033[0;32m'
BLUE='\033[0;36m'
GREY='\033[38;5;237m'
@hfossli
hfossli / WKWebViewKeyLogger.m
Created October 11, 2018 07:17
WKWebViewKeyLogger will automatically add itself to the objc runtime and add a keylogger to any WKWebView created
//
// Author: Håvard Fossli <hfossli@agens.no>
//
// Copyright (c) 2018 Agens AS (http://agens.no/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@hfossli
hfossli / date-compare.sh
Last active October 17, 2018 11:35
Get notified when new booking hours is available at Politihuset Grønland or Politihuset Sandvika
#!/bin/bash
first_is_earlier() {
y1=$(date -jf '%d.%m.%y%y' "$1" +'%Y' 2> /dev/null)
y2=$(date -jf '%d.%m.%y%y' "$2" +'%Y' 2> /dev/null)
m1=$(date -jf '%d.%m.%y%y' "$1" +'%m' 2> /dev/null)
m2=$(date -jf '%d.%m.%y%y' "$2" +'%m' 2> /dev/null)
d1=$(date -jf '%d.%m.%y%y' "$1" +'%d' 2> /dev/null)
d2=$(date -jf '%d.%m.%y%y' "$2" +'%d' 2> /dev/null)
if [ $y2 -gt $y1 ] ; then
@hfossli
hfossli / swiff.swift
Last active January 15, 2019 20:56
Blazing fast and human readable time diffs lines of output when running build commands like fastlane
#!/usr/bin/env xcrun swift
import Darwin
import Foundation
struct ANSIColors {
static let clear = "\u{001B}[0m"
static let red = "\u{001B}[38;5;160m"
static let orange = "\u{001B}[38;5;202m"
static let yellow = "\u{001B}[38;5;220m"
@hfossli
hfossli / switch.swift
Last active January 28, 2019 12:49
Switch constants easily with this swift CLI
#!/usr/bin/swift
import Foundation
struct Config {
enum Environment: String {
case dev
case prod
}
var environment: Environment = .prod
import binascii, base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat, load_pem_public_key, PrivateFormat, load_pem_private_key, NoEncryption
from cryptography.hazmat.primitives.kdf.x963kdf import X963KDF
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
@hfossli
hfossli / CGFloatEqual.m
Created May 14, 2014 11:24
CGFloatEqual
BOOL CGFloatEqual(CGFloat a, CGFloat b, CGFloat accuracy)
{
#if CGFLOAT_IS_DOUBLE
if (fabs(a-b) < accuracy * DBL_EPSILON * fabs(a+b) || fabs(a-b) < DBL_MIN)
{
return YES;
}
#else
if (fabs(a-b) < accuracy * FLT_EPSILON * fabs(a+b) || fabs(a-b) < FLT_MIN)
{
const https = require("https");
function fetchStatusCode(url) {
return new Promise(function(resolve, reject) {
const req = https.request(url, res => {
resolve(res.statusCode);
});
req.on("error", error => {
reject(error);
});
@hfossli
hfossli / AppDelegate.swift
Last active February 29, 2020 02:01
AppVersion
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
AppVersion.activateAndSaveCurrentVersion()
application.onFirstLaunch {
showWelcomeMessage()
}
application.onUpgrade { (previousVersion, currentVersion) in
migrateData(from: previousVersion, to: currentVersion)