Skip to content

Instantly share code, notes, and snippets.

Fernando Paredes nanoxd

Block or report user

Report or block nanoxd

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
nanoxd / rbenv.plugin.zsh
Created Aug 19, 2019
Plugin for rbenv on ZSH
View rbenv.plugin.zsh
rbenvdirs=("$HOME/.rbenv" "$HOME/.local/rbenv" "/usr/local/opt/rbenv" "/usr/local/rbenv" "/opt/rbenv")
for rbenvdir in "${rbenvdirs[@]}" ; do
if [ -z "$found_rbenv" ] && [ -d "$rbenvdir/versions" ]; then
if [ -z "$RBENV_ROOT" ]; then
nanoxd / Pendulum.swift
Created Mar 30, 2019
A wrapper around a repeating timer that does not require invalidation.
View Pendulum.swift
/// A wrapper around a repeating timer that does not require invalidation.
final class Pendulum {
let timer: Timer
init(seconds: TimeInterval, closure: @escaping () -> ()) {
timer = Timer.scheduledTimer(
withTimeInterval: seconds,
repeats: true,
block: { _ in
nanoxd / Request+Result.swift
Last active Mar 30, 2019
Request+Result.swift #swift
View Request+Result.swift
extension Request where Response: Decodable {
func handle(
response: Result<Data, Error>,
completion: (Result<Response, Error>) -> Void) {
completion(Result {
try JSONDecoder().decode(Response.self, from: response.get())
nanoxd / main.swift
Created Feb 7, 2019
[Assert Main Queue] Assert you're on main queue. Note that main thread and main queue are not always the same thing
View main.swift
condition: DispatchPredicate.onQueue(DispatchQueue.main)
nanoxd / Either.swift
Created Dec 22, 2018
[Either] A type representing an alternative of one of two types.
View Either.swift
/// A type representing an alternative of one of two types.
/// By convention, and where applicable, `Left` is used to indicate failure, while `Right` is used to indicate success. (Mnemonic: “right” is a synonym for “correct.”)
/// Otherwise, it is implied that `Left` and `Right` are effectively unordered alternatives of equal standing.
public enum Either<Left, Right> {
case left(Left)
case right(Right)
/// Returns the value of `Left` instances, or `nil` for `Right` instances.
nanoxd / HelloWorldViewModel.swift
Created Dec 16, 2018
[ViewModelType] Provide a clear contract between inputs/outputs desired in a view model
View HelloWorldViewModel.swift
final class HelloWorldViewModel: ViewModelType {
let input: Input
let output: Output
struct Input {
let name: Anyobserver<String>
struct Output {
let greeting: Driver<String>
nanoxd / Collection+anySatisfy.swift
Created Dec 10, 2018
[Collection.anySatisfy] With the introduction of allSatisfy, we can cleanly represent the inverse.
View Collection+anySatisfy.swift
extension Collection {
func anySatisfy(_ p: (Element) -> Bool) -> Bool {
return !self.allSatisfy { !p($0) }
nanoxd / PermutationIterator.swift
Created Dec 10, 2018
[PermutationIterator] Use of Heap's Algorithm to create permutations
View PermutationIterator.swift
public struct PermutationIterator<T>: IteratorProtocol {
private var hasReturnedInitial = false
private var a: [T]
private var c: [Int]
private let n: Int
private var i = 0
public init<C: Collection>(_ values: C) where C.Element == T {
a = Array(values)
n = a.count
nanoxd /
Last active Jun 10, 2019
[Xcode Diet] Clean up after Xcode's voracious hard drive appetite
#!/usr/bin/env sh
set -e
fancy_echo() {
local fmt="$1"; shift
printf "\n$fmt\n" "$@"
nanoxd / fix-xcode
Last active Mar 15, 2019
Xcode Scripts
View fix-xcode
#!/usr/bin/env sh
# Xcode sometimes gets sad and won't index or other shenanigans. You can easily cheer up Xcode
# and get things happy again by simply removing some files. This little script does just that.
# Quit Xcode
osascript -e 'tell app "Xcode" to quit'
# Remove derived data
rm -rf ~/Library/Developer/Xcode/DerivedData/*
You can’t perform that action at this time.