Skip to content

Instantly share code, notes, and snippets.

View alexruperez's full-sized avatar
:octocat:
Tech Director @globant

Alex Rupérez alexruperez

:octocat:
Tech Director @globant
View GitHub Profile
import SwiftUI
import PlaygroundSupport
struct ClickWheel: View {
var body: some View {
ZStack {
Circle()
.fill(LinearGradient(
gradient: Gradient(stops: [
.init(color: Color(#colorLiteral(red: 0.21568627655506134, green: 0.21568627655506134, blue: 0.21568627655506134, alpha: 1)), location: 0),
#!/bin/zsh
# The right time
xcrun simctl status_bar booted override --time 09:41
# WiFi & Cellular network
xcrun simctl status_bar booted override --dataNetwork wifi
xcrun simctl status_bar booted override --wifiBars 3
xcrun simctl status_bar booted override --cellularBars 4
# 100% battery level
xcrun simctl status_bar booted override --batteryLevel 100
@Mun0n
Mun0n / GridSpacingItemDecoration.kt
Created February 21, 2019 12:09
GridSpacingItemDecoration in kotlin for Grid RecyclerViews
import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import android.view.View
class GridSpacingItemDecoration(private val spanCount: Int, private val spacing: Int, private val includeEdge: Boolean) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view) // item position
val column = position % spanCount // item column
@nicklockwood
nicklockwood / Withable.swift
Created January 28, 2019 12:06
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@codelynx
codelynx / Runtime.swift
Last active March 6, 2024 08:48
[Swift] To retrieve classes at runtime which conforms to a protocol or to retrieve subclasses of a given class
//
// Runtime.swift
// Swift Runtime [Swift 4]
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
import Foundation
import UIKit
struct ViewStyle<T> {
let style: (T) -> Void
}
let filled = ViewStyle<UIButton> {
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .red
@pepasflo
pepasflo / .gitignore
Last active October 22, 2023 12:06
Scripts for encrypting / decrypting secrets (to prevent them from being accidentally checked into git)
secrets/
func saveEncryptedPassword(_ password: String, for account: String) {
let salt = Array("salty".utf8)
let key = try! HKDF(password: Array(password.utf8), salt: salt, variant: .sha256).calculate().toHexString()
keychainService.save(key, for: account)
}
@gonzalezreal
gonzalezreal / IndeterminateTypesWithCodable.swift
Created April 30, 2018 19:09
Indeterminate Types with Codable in Swift
import Foundation
struct ImageAttachment: Codable {
let url: URL
let width: Int
let height: Int
}
struct AudioAttachment: Codable {
let title: String
@milseman
milseman / eat_seek_peek.swift
Created February 28, 2018 20:26
Playground for Self-sliced Collections: eat/seek/peek
// Eat/seek/peek
extension Collection where SubSequence == Self, Element: Equatable {
mutating func eat() -> Element {
defer { self = self.dropFirst() }
return peek()
}
mutating func eat(_ n: Int) -> SubSequence {
let (pre, rest) = self.seek(n)
defer { self = rest }