Skip to content

Instantly share code, notes, and snippets.

@hfossli
hfossli / gist:7234623
Last active April 19, 2024 10:09
KVO on a views geometry
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 300, 200)];
view.backgroundColor = [UIColor blueColor];
[self.view addSubview:view];
[view addObserver:self forKeyPath:@"frame" options:0 context:NULL];
@hfossli
hfossli / SHA256-Bridging-Header.h
Last active April 9, 2024 01:05
AES 256 in swift 4 with CommonCrypto
#import <CommonCrypto/CommonCrypto.h>
@hfossli
hfossli / standard.sh
Last active February 8, 2024 05:19
Standard bash script format
#!/bin/bash
CLEAR='\033[0m'
RED='\033[0;31m'
function usage() {
if [ -n "$1" ]; then
echo -e "${RED}👉 $1${CLEAR}\n";
fi
echo "Usage: $0 [-n number-of-people] [-s section-id] [-c cache-file]"
@hfossli
hfossli / ASN1.swift
Created November 9, 2018 13:37
ASN1 DER encoder and decoder in swift
//
// ASN1.swift
// ASN1
//
// Created by Håvard Fossli on 29.08.2018.
// Copyright © 2018 Håvard Fossli. All rights reserved.
//
import Foundation
@hfossli
hfossli / NodeTask.swift
Last active January 2, 2024 00:27
Start a node.js server using NSTask in Swift.
import Foundation
import Cocoa
class NodeTask: NSObject {
private let processIdentifier = NSProcessInfo.processInfo().processIdentifier
private let nodeTask = NSTask()
private let readPipe = NSPipe()
private let errorPipe = NSPipe()
private let queue = dispatch_queue_create("NodeTask.output.queue", DISPATCH_QUEUE_SERIAL)
@hfossli
hfossli / SHA256.swift
Last active June 28, 2022 09:52
SHA256 in Swift
// This is a heavily altered version of SHA2.swift found in CryptoSwift.
// I tried to remove everything that is not about SHA256.
//
// --========================================================================--
//
// SHA2.swift
// CryptoSwift
//
// Created by Marcin Krzyzanowski on 24/08/14.
@hfossli
hfossli / ffmpeg_sox_reverse.sh
Last active May 12, 2022 07:32
A bash script for reversing videos using ffmpeg and sox.
#!/bin/bash
# Created by Håvard Fossli <hfossli@gmail.com> in 2013
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <http://unlicense.org/>
#
# Description
# A bash script for reversing videos using ffmpeg and sox.
#
# Keywords
@hfossli
hfossli / AutoID.swift
Created February 18, 2021 12:50
AutoID
struct AutoID: Hashable {
private var parent: AnyHashable?
private var file: String
private var line: UInt
private var column: UInt
init(parent: AnyHashable? = nil, file: String = #file, line: UInt = #line, column: UInt = #column) {
self.parent = parent
self.file = file
self.line = line
@hfossli
hfossli / SimpleTabView.swift
Last active February 10, 2021 15:32
SimpleTabView
import Foundation
import SwiftUI
struct SimpleTab<SelectionValue: Equatable & Hashable>: View, Identifiable {
var id: SelectionValue
var image: Image
var label: Text
var content: AnyView
@hfossli
hfossli / script
Created February 8, 2021 11:57
Automator script for opening mail application and printing the current open window
on run argv
tell application "Mail" to activate
tell application "System Events"
keystroke "p" using command down
delay 2
keystroke tab
keystroke tab