Skip to content

Instantly share code, notes, and snippets.

Execute these lines:

sudo sh -c 'cat > /etc/apt/sources.list.d/focal-dell.list << EOF
deb http://dell.archive.canonical.com/updates/ focal-dell public
deb http://dell.archive.canonical.com/updates/ focal-oem public
deb http://dell.archive.canonical.com/updates/ focal-somerville public
deb http://dell.archive.canonical.com/updates/ focal-somerville-melisa public
EOF'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F9FDA6BED73CDC22
@michaelhenry
michaelhenry / diff.mdown
Created April 20, 2020 23:44 — forked from ndarville/diff.mdown
Paul Heckel's Diff Algorithm

[Isolating Differences Between Files][paper]

Advantage over Other Algorithms

The diff output is more specific:

[I]f a whole block of text is moved, then all of it, rather than just the beginning and end, is detected as changed.

>The algorithm described here avoids these difficulties. It detects differences that correspond very closely to our intuitive notion of difference.

@michaelhenry
michaelhenry / HasRootNavigationController.swift
Last active October 12, 2024 02:04
UINavigationController in swiftUI.
import SwiftUI
import UIKit
protocol HasRootNavigationController {
var rootVC:UINavigationController? { get }
func push<Content:View>(view: Content, animated:Bool)
func setRootNavigation<Content:View>(views:[Content], animated:Bool)
func pop(animated: Bool)
func popToRoot(animated: Bool)
@michaelhenry
michaelhenry / NSData+Wav.h
Last active October 21, 2019 06:57
Wave Header (Audio)
@interface NSData (Wav)
- (NSData*) waveData;
@end

It often be helpful to be able to debug memory usage in Swift on Linux, for example to debug memory leaks.

This is a quick overview of how to generate a report of memory usage for your Swift app. This guide will only show you how to generate the report, not how to analyze it, it might be written up in a blog post later.

Install Valgrind

First we need to install a tool called Valgrind, which is used to trace memory usage.

@michaelhenry
michaelhenry / stt.sh
Created August 21, 2019 11:58
AZURE REST API CALL
# Reference: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-speech-to-text
subscriptionKey=SUBSCRIPTION_KEY
filename=AUDIO_FILE_NAME_WAV_PCM_FORMAT
token=$(curl -v -X POST "https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken" \
-H "Content-type: application/x-www-form-urlencoded" \
-H "Content-Length: 0" \
-H "Ocp-Apim-Subscription-Key: $subscriptionKey")
@michaelhenry
michaelhenry / MultipartData.swift
Last active November 19, 2018 15:22
MultipartData model [limitation: supports 1 item only] Reference: https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
import Foundation
class MultipartData {
let data:Data
let filename:String
let key:String
let mimeType:String
private let boundary:String
init(data:Data, key:String, filename:String, mimeType:String) {
parcelRequire=function(e,r,n){var t="function"==typeof parcelRequire&&parcelRequire,i="function"==typeof require&&require;function u(n,o){if(!r[n]){if(!e[n]){var f="function"==typeof parcelRequire&&parcelRequire;if(!o&&f)return f(n,!0);if(t)return t(n,!0);if(i&&"string"==typeof n)return i(n);var c=new Error("Cannot find module '"+n+"'");throw c.code="MODULE_NOT_FOUND",c}a.resolve=function(r){return e[n][1][r]||r};var l=r[n]=new u.Module(n);e[n][0].call(l.exports,a,l,l.exports)}return r[n].exports;function a(e){return u(a.resolve(e))}}u.isParcelRequire=!0,u.Module=function(e){this.id=e,this.bundle=u,this.exports={}},u.modules=e,u.cache=r,u.parent=t;for(var o=0;o<n.length;o++)u(n[o]);return u}({13:[function(require,module,exports) {
"use strict";var e=["Out_of_memory",0],r=["Sys_error",-1],o=["Failure",-2],t=["Invalid_argument",-3],_=["End_of_file",-4],s=["Division_by_zero",-5],a=["Not_found",-6],i=["Match_failure",-7],u=["Stack_overflow",-8],f=["Sys_blocked_io",-9],l=["Assert_failure",-10],d=["Undefined_recurs
@michaelhenry
michaelhenry / YmlRenderer.swift
Last active April 7, 2018 03:05
JSON to YML converter
extension Array where Iterator.Element == Substring {
var ancestors:[String] {
var _tempSelf = self
_tempSelf.popLast()
return _tempSelf.flatMap { $0.stringValue }
}
@michaelhenry
michaelhenry / executionTimeInterval.swift
Created January 11, 2017 08:14 — forked from kristopherjohnson/executionTimeInterval.swift
Calculate execution time for a block of Swift code
import QuartzCore
func executionTimeInterval(block: () -> ()) -> CFTimeInterval {
let start = CACurrentMediaTime()
block();
let end = CACurrentMediaTime()
return end - start
}