Skip to content

Instantly share code, notes, and snippets.

View seanlilmateus's full-sized avatar

Mateus seanlilmateus

View GitHub Profile
@HarshilShah
HarshilShah / PhotosStylePicker-Final.swift
Created December 21, 2022 10:23
A SwiftUI picker that tries to match the Years/Months/Days/All Photos palette in the Library tab of Photos for iOS
import SwiftUI
protocol TitleProvider {
var title: String { get }
}
extension ColorScheme {
var dual: ColorScheme {
switch self {
case .light: return .dark
@ole
ole / Stateful.swift
Last active December 5, 2022 20:58
A wrapper view that provides a mutable Binding to its content closure. Useful in Xcode Previews for interactive previews of views that take a Binding. https://twitter.com/olebegemann/status/1565707085849010176
import SwiftUI
/// A wrapper view that provides a mutable Binding to its content closure.
///
/// Useful in Xcode Previews for interactive previews of views that take a Binding.
struct Stateful<Value, Content: View>: View {
var content: (Binding<Value>) -> Content
@State private var state: Value
init(initialState: Value, @ViewBuilder content: @escaping (Binding<Value>) -> Content) {
@myurieff
myurieff / InputField.swift
Last active May 29, 2023 10:18
SwiftUI TCA Validated Input Field
public enum InputField<Value: Equatable> {
/// The state of current input validation
public enum InputValidation: Equatable {
/// A value that has undergone validation and is found to be valid.
case valid(Value)
/// A value that has undergone validation and is found to be invalid.
/// Optionally, a feedback message can be displayed to the user
/// to let them know what the issue with their input is.
/// For example: "Please enter a value between 10 and 100."
case invalid(Value, feedback: String?)
@seanlilmateus
seanlilmateus / ruby-redux.rb
Created July 21, 2022 20:17 — forked from eadz/ruby-redux.rb
Redux in Ruby
# Redux in Ruby
class Store
attr_reader :state
def initialize(initial_state, *reducers)
@reducers = reducers
@state = initial_state || {}
end
@JonasBernard
JonasBernard / OPEN-VPN-AND-PIHOLE.MD
Last active March 16, 2024 07:27
Docker compose setup for openVPN server with own pihole dns server.

OpenVPN and PiHole in one standalone docker-compose setup

Set up a VPN server that pomotes a pihole DNS server that is only acessible throught the vpn network.

Steps to setup the server

Edit the docker-compose.yml file

You have to replace 'insert-random-string' with a real password. Also read throught the docker-compose.yml and see if you need to make any changes to the ip adresses and ports.

@kddnewton
kddnewton / json.rb
Last active October 6, 2023 09:25
JSON parser with pattern matching
require "json"
struct = { "a" => 1, "b" => 2, "c" => [1, 2, 3], "d" => [{ "e" => 3 }, nil, false, true, [], {}] }
source = JSON.dump(struct)
tokens = []
index = 0
until source.empty?
tokens <<
//
// A Swift property wrapper for adding "indirect" to struct properties.
// Enum supports this out of the box, but for some reason struct doesn't.
//
// This is useful when you want to do something recursive with structs like:
//
// struct Node {
// var next: Node?
// }
//
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active April 20, 2024 10:41
FormatStyle in Excruciating Detail
@cjwcommuny
cjwcommuny / MacEditorTextView.swift
Created October 31, 2021 10:46
An NSTextView wrapped by SwiftUI with TextKit 2
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
* Modified by https://github.com/cjwcommuny for TextKit 2
*/
import Combine
@unrealwill
unrealwill / collisionLSH.py
Created August 8, 2021 10:20
Proof of Concept : generating collisions on a neural perceptual hash
import tensorflow as tf #We need tensorflow 2.x
import numpy as np
#The hashlength in bits
hashLength = 256
def buildModel():
#we can set the seed to simulate the fact that this network is known and doesn't change between runs
#tf.random.set_seed(42)
model = tf.keras.Sequential()