Skip to content

Instantly share code, notes, and snippets.

@tngranados
tngranados / Publisher+XCTestExpectation.swift
Created December 19, 2022 17:21
An extension to Combine's Publisher that adds a function `expectChange` that takes a predicate and returns an expectation that is fulfilled whenever that predicate evaluates true
import XCTest
import Combine
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension Publisher where Self.Failure == Never {
func expectChange(where predicate: ((Self.Output) -> Bool)? = nil, timeout: Int = 5) -> XCTestExpectation {
let expectation = XCTestExpectation(description: "something changed")
let cancellable = self.sink { value in
guard let predicate else {
@tngranados
tngranados / schema.json
Created October 13, 2022 07:25
A GraphQL schema that apollo-ios 1.0.0 fails to generate code correctly
{
"data": {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": {
"name": "Mutation"
},
"subscriptionType": null,

The app will consistent in a simple list with a detail view when tapping on a cell. The list content will be retrieved from an API when the app starts. It should show some kind of loading indicator to the user.

The API endpoint is: https://api.instantwebtools.net/v1/passenger?page=0&size=30

This API is paginated, you can get the next pages changing the query parameter.

The API returns a list of passengers of an airline. The list will show the names of the passengers and the detail view will include extra information like the number of trips or some information about the airline.

This is an example response from the API:

@tngranados
tngranados / .zshrc
Created December 16, 2020 08:17
Run every check before merging a PR
lgtm() {
yarn lint || { echo -e '\n\n \e[31mSomething went wrong: javascript linting\e[m \n\n' && return false }
rubocop -a || { echo -e '\n\n \e[31mSomething went wrong: ruby linting\e[m \n\n' && return false }
yarn test || { echo -e '\n\n \e[31mSomething went wrong: javascript testing\e[m \n\n' && return false }
rspec || { echo -e '\n\n \e[31mSomething went wrong: ruby testing\e[m \n\n' && return false }
if [[ -n $(git status -s) ]]; then
git status
echo -e '\n\n \e[33mAll good, but git status is dirty\e[m \n\n'
else
@tngranados
tngranados / zsh static server.sh
Last active February 4, 2020 16:17
ZSH static server
# Creates a static server using ruby, php, or python 2 or 3, whichever is
# available. It support an optional port (default is 8000).
shttp() {
local port="${1:-8000}"
if (( $+commands[ruby] )); then
ruby -run -ehttpd . -p$port
elif (( $+commands[php] )); then
php -S localhost:$port
elif (( $+commands[python] )); then
local pythonVer=$(python -c 'import platform; major, _, _ = platform.python_version_tuple(); print(major);')
@tngranados
tngranados / Karabiner tngranados.json
Last active February 5, 2020 08:19
Karabiner spaces control with mouse back/forward button plus cmd
{
"title": "Personal Karabiner configuration",
"rules": [
{
"description": "When the back mouse button is clicked while cmd is held down, post a ctrl+left.",
"manipulators": [
{
"type": "basic",
"from": {
"pointing_button": "button4",
@tngranados
tngranados / iTerm keys presset.itermkeymap
Last active January 31, 2020 12:42
The iTerm2 keys presset I use in conjuction with my zsh config
{
"Touch Bar Items": [
],
"Key Mappings": {
"0xf703-0x280000": {
"Text": "altright",
"Action": 10
},
"0xf729-0x0": {
@tngranados
tngranados / certgen.go
Created November 21, 2019 11:31
Go Fake Certificate test generation
package certgen
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"io/ioutil"
@tngranados
tngranados / cloudSettings
Last active July 23, 2020 11:29
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-07-23T11:29:15.736Z","extensionVersion":"v3.4.3"}