Skip to content

Instantly share code, notes, and snippets.

View arthurpalves's full-sized avatar
👨‍💻

Arthur Alves arthurpalves

👨‍💻
View GitHub Profile
@arthurpalves
arthurpalves / NegaBinary.java
Last active February 5, 2016 16:26
Negate a negative based binary (base -2) using Two's Complement Annotation.
package com.codility.tasks;
/*
Negate a negative based binary (base -2) using Two's Complement Annotation.
Given a base -2 number splitted into a primitive array of ints (int[]), return it's negation.
EXAMPLES:
INPUT: [0,1,0,0,1,1,1] // Decimal 39.
OUTPUT: [1,0,1,1,0,0,1] // Decimal -39.
@arthurpalves
arthurpalves / SyntaxVisitor.swift
Created May 27, 2020 07:40
SyntaxVisitor_visitPost(_:ClassDeclSyntax)
/// The function called after visiting `ClassDeclSyntax` and its descendents.
/// - node: the node we just finished visiting.
open func visitPost(_ node: ClassDeclSyntax) {}
override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
// Do something with a class node
return .visitChildren
}
override func visit(_ node: ExtensionDeclSyntax) -> SyntaxVisitorContinueKind {
// Do something totally different with an extension node
return .visitChildren
}
@arthurpalves
arthurpalves / SyntaxVisitor.swift
Created May 27, 2020 07:45
open func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind
/// Visiting `ClassDeclSyntax` specifically.
/// - Parameter node: the node we are visiting.
/// - Returns: how should we continue visiting.
open func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
return .visitChildren
}
public enum SyntaxVisitorContinueKind {
/// The visitor should visit the descendents of the current node.
case visitChildren
/// The visitor should avoid visiting the descendents of the current node.
case skipChildren
}
[{
"balance": "4675",
"IBAN": "NL27AAAA0352734310",
"currency": "EUR",
"id": "8ab78900f99013a",
"name": "Main Account",
"type": "main"
}]
struct SimpleEntry: TimelineEntry {
public let date: Date
}
struct AccountEntry: TimelineEntry {
public let date: Date
public let product: Product
}
enum ProductType {
case main, secondary
}
struct Product: Identifiable {
let id: String
let name: String
let balance: Double
let iban: String
let type: ProductType
struct Provider: TimelineProvider {
public typealias Entry = SimpleEntry
public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
/* implementation */
}
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
/* implementation */
}