Skip to content

Instantly share code, notes, and snippets.

Plug.Conn.Query.encode(%{a: [%{b: 2, c: 3}]}) == Plug.Conn.Query.encode(%{a: [%{b: 2}, %{c: 3}]}) #=> true
container.register(Repository.self) { c in
if getEnv() == "LOCAL" { // Just an example of how a check for running environment could possibly be
return MockGithubRepository()
} else {
let localCache = c.resolve(LocalCache.self)!
let api = c.resolve(GithubAPI.self)!
return GithubRepository(cache: localCache, api: api)
}
}
@migore
migore / mock.swift
Last active February 22, 2016 17:16
protocol Repository {}
class MockGithubRepository : Repository {}
class GithubRepository : Repository {
// all repository things that were already here
}
class GithubAPI {}
class LocalCache {}
class Repository {
var api: GithubAPI
var cache: LocalCache
init(cache: LocalCache, api: GithubAPI) {
self.cache = cache
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
container = Container()
container.register(GithubAPI.self) { c in
GithubAPI()
}
container.register(LocalCache.self) { c in
LocalCache()
}
// Snippet taken from https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html
let margins = view.layoutMarginsGuide
myView.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor).active = true
myView.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor).active = true
myView.heightAnchor.constraintEqualToAnchor(myView.widthAnchor, multiplier: 2.0)
// Snippet taken from https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/ProgrammaticallyCreatingConstraints.html
let views = ["myView" : myView]
let formatString = "|-[myView]-|"
let constraints = NSLayoutConstraint.constraintsWithVisualFormat(formatString, options:.AlignAllTop , metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(constraints)
welcomeLabel.textAlignment = .Center
welcomeLabel.snp_makeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.top.equalTo(view).offset(80)
make.height.equalTo(50)
}
someImageView.snp_makeConstraints { make in
make.top.equalTo(welcomeLabel.snp_bottom).offset(40)
@migore
migore / robot.js
Created December 5, 2012 18:40
Name
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(200);
@migore
migore / robot.js
Created December 5, 2012 18:40
Name
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(200);