This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func memoize<T: Hashable,U>(function: @escaping (T) -> U) -> (T) -> U{ | |
var cache : [T:U] = [:] | |
func memoWrapper(input: T) -> U { | |
if let cacheValue = cache[input] { | |
print("used cached result") | |
return cacheValue | |
} | |
let newVal = function(input) | |
cache[input] = newVal | |
print("new result") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIColor { | |
class func rgb(_ red: Int, _ green: Int, _ blue: Int) -> UIColor { | |
return UIColor.rgba(red,green,blue,1.0) | |
} | |
class func rgba(_ red: Int, _ green: Int, _ blue: Int, _ alpha: Float) -> UIColor { | |
return UIColor.init(colorLiteralRed: Float(red)/255.0, green: Float(green)/255.0, blue: Float(blue)/255.0, alpha:alpha) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension WKInterfaceController { | |
func animate(withDuration duration: TimeInterval, animations: @escaping () -> Swift.Void, completion: @escaping () -> Swift.Void) { | |
self.animate(withDuration: duration, animations: animations) | |
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration, execute: completion) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Foundation | |
//set up | |
extension Array { | |
func filterMap<U>(transform: (T) -> U?) -> [U] { | |
var mapped = [U]() | |
for item in self { | |
if let unwrapped = transform(item) { | |
mapped.append(unwrapped) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ProtocolA { | |
init() | |
} | |
class classA : ProtocolA { | |
required init() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given | |
protocol ProtocolA { | |
static var foo : String { get } | |
} | |
protocol ProtocolB { | |
static var bar : String { get } | |
} | |
//I want a function that will only accept types that impliment both protocols | |
class TypeA : ProtocolA, ProtocolB { | |
static var foo : String { get{ return "foo"} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) addFakeContacts{ | |
ABAddressBookRef addressBook = ABAddressBookCreate(); | |
// create 200 random contacts | |
for (int i = 201; i < 400; i++) | |
{ | |
// create an ABRecordRef | |
ABRecordRef record = ABPersonCreate(); | |
ABMutableMultiValueRef multi = ABMultiValueCreateMutable(kABStringPropertyType); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?\> | |
<!-- All runtime environments that use this package are required to supply--\> | |
<!-- real implementations of these interfaces at runtime--\> | |
<beans xmlns="http://www.springframework.org/schema/beans"\> | |
<bean id="datasource" class="test.mock.Datasource" | |
destroy-method="close" autowire-candidate="false"\> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.spring; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.support.ClassPathXmlApplicationContext; | |
import javax.sql.DataSource; | |
public class ApplicationContext { | |
static final String[] CONTEXT_FILES = new String[] {"datasource.xml","beans.xml"}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchManifests() { | |
for jarFile in \`ls $1/\*jar\`; | |
do echo $jarFile; unzip -p $jarFile META-INF/MANIFEST.MF | | |
perl -e ' | |
while(){ | |
if($\_ =\~ /$ARGV[0]:\\s([\^\\s]\*)\\s/){ | |
print " " .$1 . "\\n"; exit; | |
} | |
} | |
print " no match \\n"; ' $2; done |
NewerOlder