Skip to content

Instantly share code, notes, and snippets.

View hugocf's full-sized avatar

Hugo Ferreira hugocf

View GitHub Profile
@mchambers
mchambers / serializer.swift
Created June 25, 2014 07:49
A simple, limited model-to-JSON serializer in Swift.
// Here we'll use Swift's IDE-supporting reflect()
// function to build a basic JSON serializer.
// Per the fine engineers at WWDC, Swift's reflection support
// exists purely to support the IDE and the Playground. But
// we can have some fun with it anyway. ;)
class SerializerBase {
}
@nicklockwood
nicklockwood / gist:7446228
Last active December 28, 2015 04:59
Why having a single success/error callback block is better than having separate ones

Suppose you have a network method that only uses a single block callback

typedef void (^Handler)(BOOL success, id response, NSError *error);

- (void)makeRequestWithHandler:(Handler)handler;

But you have to make this request dozens of times, and you want to reuse the same failure handler in most cases? Easy, just have a factory function that returns a block:

typedef void (^SuccessHandler)(id response);

typedef void (^ErrorHandler)(NSError *error);

@bsneed
bsneed / Timings.txt
Last active January 9, 2016 17:29
Performance Comparison of Swift JSON->Model frameworks.
Time to decode 10,000 Person struct's from JSON:
Argo (Simple): 8.563 seconds
measureBlock {
let _ : [Person]? = decode(data)
}
Argo (Decomp'd): 3.344
measureBlock {
let json: Argo.JSON = JSON.parse(data)
@mluisbrown
mluisbrown / main.swift
Created July 10, 2016 11:58
Swift code to find and count all Circular Primes below 1 million (Project Euler problem 35)
// Circular primes
// Problem 35
// The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
//
// There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.
//
// How many circular primes are there below one million?
import Foundation
//: Playground - noun: a place where people can play
import UIKit
struct Domino {
let left: Int
let right: Int
init(string: String) {
let split = string.componentsSeparatedByString("-")
@ccgus
ccgus / gist:3238464
Created August 2, 2012 16:37
FMDB custom functions
[db makeFunctionNamed:@"UTTypeConformsTo" maximumArguments:2 withBlock:^(sqlite3_context *context, int argc, sqlite3_value **argv) {
if (sqlite3_value_type(argv[0]) == SQLITE_TEXT) {
const unsigned char *a = sqlite3_value_text(argv[0]);
const unsigned char *b = sqlite3_value_text(argv[1]);
CFStringRef as = CFStringCreateWithCString(0x00, (const char*)a, kCFStringEncodingUTF8);
CFStringRef bs = CFStringCreateWithCString(0x00, (const char*)b, kCFStringEncodingUTF8);
sqlite3_result_int(context, UTTypeConformsTo(as, bs));
@rcarmo
rcarmo / archive.txt
Created March 18, 2016 23:07
Epic Commits from @dramalho
061997d DELEGATE ALL THE THINGS
092aa231f wait, wrong place
09e7fd3 RERECORD ALL THE THINGS!!!
0c27fb3 yeah, fix things will ya
0f4549133 New ascii art task (\!important stuff) , and a few DAO tweaks (mino...
12aa7ef34 LE NONNNNNN LE MADNESS
13233e7 Less PHP
154c535 Once more, now with feeling and a proper master head
184e754 Dear Past-Friday David :Remember the textarea that seemed totally random and misterioys? It was $.ajax... obviously
19a8700 MAKE IT BIGGER
@darkliquid
darkliquid / beautified.js
Last active August 22, 2019 02:28
Bookmarklet to estimate reading time of a page
javascript:(function () {
function getTextNodesIn(element) {
var wordcount = 0,
whitespace = /^\s*$/;
function getTextNode(node) {
// type 3 is a textnode
if (node.nodeType == 3) {
// We skip text nodes that are only whitespace
if (!whitespace.test(node.nodeValue)) {
@chbm
chbm / legislativas2019.md
Last active September 18, 2019 18:33
Legislativas 2019 - Direitos digitais

Eleições Legislativas 2019 - Direitos digitais

Introdução

Os direitos digitais e as garantias democráticas são, a seguir à emergência climática e à resposta da sociedade aos novos modelos de trabalho, uma area da política actual que vai definir as próximas décadas. Resumo aqui as posições dos partidos que concorrem às eleições legislativas 2019. Não sou um observador isento por isso classifico cada proposta tendo como critério o acesso livre e sem censura à informação, e as garantias de proteção da vida privada.

PSD

Nota: E

@nunogoncalves
nunogoncalves / CreditCardValidation.swift
Last active October 7, 2021 07:51
Credit card validation in Swift 3
import UIKit
import PlaygroundSupport
//http://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number
enum CreditCardType {
case visa
case visaElectron
case mastercard