Skip to content

Instantly share code, notes, and snippets.

View klefevre's full-sized avatar

Kévin Lefèvre klefevre

View GitHub Profile
@pudquick
pudquick / brew.md
Last active April 6, 2024 21:42
Lightly "sandboxed" homebrew on macOS

brew is a bad neighbor

This isn't a guide about locking down homebrew so that it can't touch the rest of your system security-wise.

This guide doesn't fix the inherent security issues of a package management system that will literally yell at you if you try to do something about "huh, maybe it's not great my executables are writeable by my account without requiring authorization first".

But it absolutely is a guide about shoving it into its own little corner so that you can take it or leave it as you see fit, instead of just letting the project do what it likes like completely taking over permissions and ownership of a directory that might be in use by other software on your Mac and stomping all over their contents.

By following this guide you will:

  • Never have to run sudo to forcefully change permissions of some directory to be owned by your account
import Foundation
protocol Settings {
subscript(key: String) -> AnyObject? { get nonmutating set }
}
struct Defaults: Settings {
typealias Set = (String, AnyObject?) -> Void
typealias Get = (String) -> AnyObject?
@martinth
martinth / argparse_fileinput_demo.py
Created August 6, 2015 11:04
Read from stdin or files in Python (combining argparse and fileinput)
import argpase
import fileinput
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--dummy', help='dummy argument')
parser.add_argument('files', metavar='FILE', nargs='*', help='files to read, if empty, stdin is used')
args = parser.parse_args()
# If you would call fileinput.input() without files it would try to process all arguments.
@stevenschobert
stevenschobert / camel_case.swift
Last active July 30, 2023 13:09
Camel-case a string in Swift
func camelCaseString(source: String) -> String {
if contains(source, " ") {
let first = source.substringToIndex(advance(source.startIndex, 1))
let cammel = NSString(format: "%@", (source as NSString).capitalizedString.stringByReplacingOccurrencesOfString(" ", withString: "", options: nil, range: nil)) as String
let rest = dropFirst(cammel)
return "\(first)\(rest)"
} else {
let first = (source as NSString).lowercaseString.substringToIndex(advance(source.startIndex, 1))
let rest = dropFirst(source)
return "\(first)\(rest)"
@zwaldowski
zwaldowski / NSObject+Blocks.h
Created May 4, 2011 12:08
Perform blocks with delays and cancellation
//
// NSObject+Blocks.h
// Filemator
//
// Created by Zachary Waldowski on 4/12/11.
// Copyright 2011 Dizzy Technology. All rights reserved.
//
@interface NSObject (Blocks)