Skip to content

Instantly share code, notes, and snippets.

View aciidgh's full-sized avatar

Ankit Aggarwal aciidgh

View GitHub Profile
@aciidgh
aciidgh / Lockfile.md
Created March 8, 2016 22:48
Lock file proposal

Lock File for Swift Package Manager

Introduction

A Lockfile file locking the state of resolved dependencies generated by swiftpm.

Motivation

Lockfile file can be helpful in situations like :

$ pkgutil --expand swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx.pkg swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx
$ cd swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx
$ cd swift-DEVELOPMENT-SNAPSHOT-2016-03-01-a-osx-package.pkg
$ mv Payload Payload.zip
$ open .
double click to extract
$ cd Payload\ 2/usr/bin
$ ./swiftc -v
Apple Swift version 3.0-dev (LLVM b361b0fc05, Clang 11493b0f62, Swift 24a0c3de75)
import Foundation
public func getASTString() -> String {
// get the file path for the file "test.json" in the playground bundle
// let filePath = NSBundle.mainBundle().pathForResource("FirstTtest", ofType: "ast")
// get the contentData
let contentData = NSFileManager.defaultManager().contentsAtPath("a.txt")
//func ptrFromAddress<T>(p:UnsafeMutablePointer<T>) -> UnsafeMutablePointer<T> { return p }
//var buf = [CChar]()
////put some stuff in the buffer
//buf.append(CChar(0)) //CRITICAL or you'll overrun the buffer on the next line
//
//var mystr = "Dd"
@aciidgh
aciidgh / environ.swift
Created January 26, 2016 19:31
environ using dlsym
import Darwin
import Foundation
let environ: UnsafePointer<UnsafePointer<CChar>> = UnsafePointer(dlsym(UnsafeMutablePointer(bitPattern: Int(-2)), "environ"))[0]
var iterator = environ
while iterator.memory != nil {
print(String.fromCString(iterator.memory))
iterator = iterator.successor()
protocol TagView {
var view: UIView { get }
}
protocol ViewConvertible {
func getView() -> UIView
}
struct ViewModel<T: ViewConvertible>: TagView {
protocol StoryboardInstantiable {
static var storyboardID: String { get }
static func instance(storyboard: UIStoryboard) -> Self?
}
extension StoryboardInstantiable {
static func instance(storyboard: UIStoryboard) -> Self? {
return storyboard.instantiateViewControllerWithIdentifier(Self.storyboardID) as? Self
}
}
$ swift
Welcome to Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 54dcd16759). Type :help for assistance.
1> let a = 5
a: Int = 5
2> a
$R0: Int = 5
3> let a = "hello"
a: String = "hello"
4> a
$R1: String = "hello"
─aciid@AciidHome ~/mycode/swift.org/swift/stdlib/public ‹master›
╰─$ grep -r ".None" .
./common/MirrorBoilerplate.gyb:% genericArgs if 'genericArgs' in locals() else None,
./common/MirrorBoilerplate.gyb:% genericConstraints if 'genericConstraints' in locals() else None)
./common/MirrorBoilerplate.gyb:% disposition if 'disposition' in locals() else None)
./common/MirrorBoilerplate.gyb:var objectIdentifier: ObjectIdentifier? { return .None }
./common/MirrorCommon.py:def getDisposition(disp=None):
./common/MirrorCommon.py: if disp is None:
./common/MirrorCommon.py:def _getGenericArgStrings(genericArgs=None, genericConstraints=None):
./common/MirrorCommon.py: if genericArgs is None:
@aciidgh
aciidgh / SwiftStack.swift
Created January 2, 2016 15:59
A generic stack in swift
protocol StackType {
typealias Element
mutating func push(element: Element)
mutating func pop() -> Element?
}
final class BufferStorage<Element> {
private var ptr: UnsafeMutablePointer<Element>
private let capacity: Int