Skip to content

Instantly share code, notes, and snippets.

Nuno Gonçalves nunogoncalves

Block or report user

Report or block nunogoncalves

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nunogoncalves
nunogoncalves / AdminEmailExpectation
Created Jul 7, 2014
Rspec test which is expecting an email to be sent to email
View AdminEmailExpectation
it 'sends email to admin with error response' do
VCR.use_cassette('external_service_response_cassette/invalid_requests', record: :new_episodes) do
Hash.any_instance.stub(:value_from_params).and_raise(ExceptionType, "Failed to find key in params")
params1 = 'AdminMailer'
params2 = 'errors'
params3 = 'Error message: There has been an error'
SendEmailWorker.should_receive(:perform_async).with(params1, params2, params3).exactly(1).times
@nunogoncalves
nunogoncalves / WeakClosures.playground
Last active Aug 29, 2015
Gist to avoid Strong Reference Cycles when using closures
View WeakClosures.playground
//: Playground - noun: a place where people can play
import UIKit
class LoginView {
var loginSuccessCallback: ((Int)->Void)?
init() {
println("login: - hello")
@nunogoncalves
nunogoncalves / gist:f360c0faafaeea7c46b8
Created Oct 30, 2015 — forked from sonsongithub/gist:2868639
Parse Xcode project file, project.pbxproj, in Ruby.
View gist:f360c0faafaeea7c46b8
json = JSON.parse(`plutil -convert json -o - "#{filename}"`)
@nunogoncalves
nunogoncalves / Loading elipsis animation.swift
Last active Dec 23, 2015
Setting an ellipsis changing from 1 to 3 dots
View Loading elipsis animation.swift
//Set a NSTimer to update call this function every n seconds to provide desired effect.
var numberOfDots = 3
func applySearchingEffect() {
if let str = label.text {
let range = NSMakeRange(str.length - numberOfDots, numberOfDots)
var string = NSMutableAttributedString(string: str)
string.addAttribute(NSForegroundColorAttributeName, value: UIColor.clearColor(), range: range)
label.attributedText = string
@nunogoncalves
nunogoncalves / MultipleRequesters.swift
Last active Dec 31, 2015
Creating multiple requesters with default behaviour using protocol extensions
View MultipleRequesters.swift
import Foundation
protocol Getter {
typealias Element
func getUrl() -> String
func getDataFrom(dictionary: NSDictionary) -> Element
func get(success success: Element -> (), failure: () -> ())
}
extension Getter { //Add default behaviour to Getter protocol. This behaviour depends on implementation of other protocol methods.
View get_languages_original.swift
struct Languages {
func get(success success: [Language] -> (),
failure: NetworkStatus -> ()) {
let qos = Int(QOS_CLASS_USER_INTERACTIVE.rawValue)
dispatch_async(dispatch_get_global_queue(qos, 0)) {
let responseHandler = ResponseHandler()
responseHandler.failureCallback = { status in
View languages_get_protocol_ext.swift
struct Languages {
class Get: Getter {
func getUrl() -> String {
return "http://some_languages_website.com"
}
func getDataFrom(dictionary: NSDictionary) -> [Language] {
return extractLanguagesFrom(dictionary)
View getter_protocol.swift
import Foundation
protocol Getter {
typealias Element
func getUrl() -> String
func getDataFrom(dictionary: NSDictionary) -> Element
func get(success success: Element -> (), failure: NetworkStatus -> ())
@nunogoncalves
nunogoncalves / HOWTO.md
Created Mar 20, 2016 — forked from tdantas/HOWTO.md
Too Many Connections Postgresql ( HomeBrew Installation)
View HOWTO.md

HOWTO avoid 'too many connections'


Ask postgresql where is the configuration file

$ psql postgres
 psql (9.2.2)
   Type "help" for help.
View Authenticable.swift
protocol Authenticable {
var headers: HeadParams? {
get
}
func fillHeaders()
}
extension Authenticable {
var headers: HeadParams? {
You can’t perform that action at this time.