Skip to content

Instantly share code, notes, and snippets.

View sowenjub's full-sized avatar
🏝️
Living in Paraside

Arnaud Joubay sowenjub

🏝️
Living in Paraside
View GitHub Profile
@sowenjub
sowenjub / fun_with_splats.rb
Last active February 24, 2021 19:12
Some notes about the splat operator
def args_to_array(*args)
p args
end
args_to_array("hello", "world")
# ["hello", "world"]
def args_to_array(foo, *args) # Works, order matters
p "foo: #{foo}", args
end
args_to_array("hello", "world")
# mailboxes/concerns/mail_params.rb
module MailParams
extend ActiveSupport::Concern
def mail_params
attachments = build_attachments
body = build_rich_body(attachments)
{ subject: mail.subject, body: body, attachments: attachments.map { |a| a[:blob] } }
end
struct UIElementPreview<Value: View>: View {
enum Format {
case device, sizeThatFits, darkMode, rightToLeft, localizations, contentSizes, contentSizesMinMax
}
var formats: [Format]
/// Filter out "base" to prevent a duplicate preview.
private let localizations = Bundle.main.localizations.map(Locale.init).filter { $0.identifier != "base" }
@sowenjub
sowenjub / SettingsSection
Created April 27, 2022 11:06
Toggling a Diagnostic Mode button in SwiftUI using Settings.bundle
struct SettingsSection: View {
@State var isShowingCloudLink = false
var body: some View {
Section {
if isShowingCloudLink {
NavigationLink(destination: CloudSettingsView()) {
Label(…)
}
}
@sowenjub
sowenjub / Font+Fraction.swift
Created January 24, 2023 09:33
An extension to display fractions in SwiftUI. This is the answer I posted on https://stackoverflow.com/questions/71359423/how-can-i-show-a-fraction-with-swiftui/75219519#75219519
import SwiftUI
extension UIFont {
static func fractionFont(ofSize pointSize: CGFloat) -> UIFont {
let systemFontDesc = UIFont.systemFont(ofSize: pointSize).fontDescriptor
let featureSettings: [UIFontDescriptor.FeatureKey: Int] = [
.type: kFractionsType,
.selector: kDiagonalFractionsSelector,
]
let attributes = [
@sowenjub
sowenjub / ci_post_xcodebuild.sh
Created January 25, 2024 17:25
Uploading dSYMs files to Sentry with Xcode Cloud
#!/bin/sh
# Don't forget to run 'chmod +x ci_post_xcodebuild.sh' from the terminal after adding this file to your project
set -e
if [[ -n $CI_ARCHIVE_PATH ]];
then
# Install Sentry CLI into the current directory ($CI_PRIMARY_REPOSITORY_PATH/ci_scripts)
export INSTALL_DIR=$PWD
@sowenjub
sowenjub / ScrollViewThatFits.swift
Created February 28, 2024 08:34
ScrollViewThatFits
import SwiftUI
struct ScrollViewThatFits<Content: View>: View {
var showsIndicators: Bool
@ViewBuilder
var content: Content
init(showsIndicators: Bool = false, @ViewBuilder content: () -> Content) {
self.showsIndicators = showsIndicators
import XCTest
extension XCTestCase {
@discardableResult
func launchApp(extraArguments: [String] = [], environment: [String: String] = [:]) -> XCUIApplication {
let app = XCUIApplication()
app.launchArguments = [
"-isAspirinShot"
]
app.launchArguments += extraArguments