Skip to content

Instantly share code, notes, and snippets.

View mlavergn's full-sized avatar
🎯
Focusing

Marc Lavergne mlavergn

🎯
Focusing
View GitHub Profile
### Keybase proof
I hereby claim:
* I am mlavergn on github.
* I am mlavergn (https://keybase.io/mlavergn) on keybase.
* I have a public key whose fingerprint is 8322 4DCC 903F A130 6B31 F5F8 1324 A1FE 3100 63E2
To claim this, I am signing this object:
@mlavergn
mlavergn / CommitGuidelines.md
Last active November 16, 2016 15:38
Commit Guidelines
Commit messages for issues with an issue number should be prefixed in the form:

  proj://issue/123 hello world

If no open issue exists, the commit should indicate the nature of the change:

  Add: Add / update files
  Del: Remove files
 Fix: Bug fix
@mlavergn
mlavergn / xc
Last active November 19, 2019 15:21
Xcode switcher which uses Make as it's interpreter while leveraging xcodebuild and xcode-select
#!/usr/bin/make -f
.DEFAULT_GOAL := main
# eval trick to avoid re-execing variable
SEL = $(eval SEL := $$(shell read sel && echo $$$$sel))$(SEL)
102:
sudo xcode-select -s /Applications/Xcode-102-10E125.app
xcodebuild -version
@mlavergn
mlavergn / SleepSort.swift
Created November 14, 2019 17:44
Swift Sleep Sort
import Foundation
// O(n) sort
// Technically O(n) since time measures complexity and not a fixed interval
// NOTE: This is just for fun, please don't use this in real applications!
func sleepSort(_ vals: [Int]) -> [Int] {
var result: [Int] = []
let sortDispatch = DispatchQueue(label: "sleepSort", qos: .userInitiated, attributes: .concurrent)
let sortGroup = DispatchGroup()
@mlavergn
mlavergn / swiftcombine.swift
Created November 21, 2019 02:21
Swift Combine demo with RxSwift commenting
import Foundation
import Combine
// register the observable name
extension Notification.Name {
static let DemoObservable = Notification.Name("DemoObservable")
}
// define the observable value type
struct DemoValue {
@mlavergn
mlavergn / swiftcombinewrap.swift
Last active November 21, 2019 04:33
Swift Combine wrapped to be RxSwift-like
import Foundation
import Combine
// define the observable value type
struct DemoValue {
var value: String
}
// observable class
class DemoObservable {
@mlavergn
mlavergn / xcsupport.sh
Last active April 8, 2020 17:47
Xcode add support for newer iOS target to an older XC release
#
# pseudo-script on adding support for a new iOS ver to an older Xcode
#
XCNEW="Xcode-113-11C505.app"
XCOLD="Xcode-110-11A420a.app"
IOSVER="13.3"
# rm -r /Applications/$XCOLD/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/$IOSVER
# cp -R /Applications/$XCNEW/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/$IOSVER /Applications/$XCOLD/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
@mlavergn
mlavergn / nohup.sh
Created January 15, 2020 16:07
nohup script template
#!/bin/sh
/usr/bin/nohup /opt/foo/bar < /dev/null >log.txt 2>&1 &
@mlavergn
mlavergn / SwiftC.swift
Created February 28, 2020 18:00
Swift C Direct Calls
// silgen allows you to call C functions without headers or bridges
// not to be used as a rulem but might have some interesting use cases
@_silgen_name("getpid") private func getpid() -> pid_t
print(getpid())
@mlavergn
mlavergn / AuthExecObjc.m
Created March 22, 2020 23:36
Objective-C AuthorizationExecuteWithPrivileges skeleton code
#import <Foundation/Foundation.h>
#import <Security/Security.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
AuthorizationRef authorizationRef;
OSStatus status;
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
if (status != errAuthorizationSuccess) {