Skip to content

Instantly share code, notes, and snippets.

@bleft
bleft / bootableUSBfromISO.txt
Created December 23, 2016 08:31
create bootable usb device from iso with macOS
hdiutil convert -format UDRW -o /pfad/der/ZIELDATEI.img /pfad/der/QUELLDATEI.iso
mv /pfad/der/KONVERTIERTENDATEI.img.dmg /pfad/der/NEUENDATEI.img
diskutil list
diskutil unmountDisk /dev/disk?
sudo dd if=/pfad/der/DATEI.img of=/dev/rdisk? bs=1m
@bleft
bleft / Data+Extension.swift
Created December 14, 2016 13:19
get md5 hash from Data in swift
extension Data {
var md5 : String {
var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH))
_ = self.withUnsafeBytes { bytes in
CC_MD5(bytes, CC_LONG(self.count), &digest)
}
var digestHex = ""
for index in 0..<Int(CC_MD5_DIGEST_LENGTH) {
digestHex += String(format: "%02x", digest[index])
}
@bleft
bleft / UIView-With-AVPlayerController.swift
Created November 8, 2016 09:30
recognizes when a AVPlayerController changes to full screen or back. There you can handle auto rotation behavior or other smart things
// add your view as observer
func addVideoBoundsObserver(){
playerController?.contentOverlayView?.addObserver(self, forKeyPath: "bounds", options: .new, context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "bounds" {
guard let new = change?[NSKeyValueChangeKey.newKey] as? CGRect
else { return }
@bleft
bleft / TimeInterval-extension.swift
Last active November 8, 2016 22:11
extends TimeInterval with durationString that returns a human readable duration in decimal or time format (HH:MM:SS)
extension TimeInterval {
func durationString(_ decimal: Bool) -> String {
if decimal {
let formatter = NumberFormatter()
formatter.minimumFractionDigits = 2
formatter.maximumFractionDigits = 2
formatter.minimumIntegerDigits = 1
let a = self / 3600
return formatter.string(from: NSNumber(value: a))! + " h"
@bleft
bleft / gist:7c41b71ec088fc52ed697cef0d8d2ef5
Last active June 21, 2016 11:56 — forked from subsetpark/gist:367f0d3fde503a1e481c
Building Python 2.7.10 on Ubuntu 14.04 LTS
$ sudo apt-get install -y gcc-multilib g++-multilib libffi-dev libffi6 libffi6-dbg python-crypto python-mox3 python-pil python-ply libssl-dev zlib1g-dev libbz2-dev libexpat1-dev libbluetooth-dev libgdbm-dev dpkg-dev quilt autotools-dev libreadline-dev libtinfo-dev libncursesw5-dev tk-dev blt-dev libssl-dev zlib1g-dev libbz2-dev libexpat1-dev libbluetooth-dev libsqlite3-dev libgpm2 mime-support netbase net-tools bzip2
$ wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
$ tar xvf Python-2.7.10.tgz
$ cd Python-2.7.10/
$ ./configure --prefix /usr/local/lib/python2.7.10 --enable-ipv6
$ make
$ sudo make install
@bleft
bleft / debuging.swift
Created May 25, 2016 14:26
Debug CFNetwork
setenv("CFNETWORK_DIAGNOSTICS", "3", 1) // in AppDelegate „didFinishLaunchingWithOptions“ einbinden.
@bleft
bleft / git-help.txt
Last active April 21, 2017 09:08
git: change branch to master
The problem with the other two answers is that the new master doesn't have the old master as an ancestor, so when you push it, everyone else will get messed up. This is what you want to do:
git checkout better_branch
git merge --strategy=ours master # keep the content of this branch, but record a merge
git checkout master
git merge better_branch # fast-forward master up to the merge
If you want your history to be a little clearer, I'd recommend adding some information to the merge commit message to make it clear what you've done. Change the second line to:
git merge --strategy=ours --no-commit master
@bleft
bleft / NSURLSessionDelegate.swift
Created May 10, 2016 08:56
URLSession Delegate for authentication challenge
func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
if challenge.protectionSpace.authenticationMethod == (NSURLAuthenticationMethodServerTrust) {
let serverTrust:SecTrustRef = challenge.protectionSpace.serverTrust!
let certificate: SecCertificateRef = SecTrustGetCertificateAtIndex(serverTrust, 0)!
let remoteCertificateData = CFBridgingRetain(SecCertificateCopyData(certificate))!
let cerPath: String = NSBundle.mainBundle().pathForResource("xyz.com", ofType: "cer")!
let localCertificateData = NSData(contentsOfFile:cerPath)!
@bleft
bleft / showFontNames.swift
Created March 11, 2016 10:26
all fonts available for app
for family: String in UIFont.familyNames()
{
print("\(family)")
for names: String in UIFont.fontNamesForFamilyName(family)
{
print("== \(names)")
}
}
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
source ~/.bash_alias #get aliases