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 / 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
@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 / 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 / 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(…)
}
}
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" }
# 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
@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")
= f.label :email, required: true, class: "block text-xxs uppercase text-gray-500" do |label_builder|
= label_builder.translation
span.ml-2.normal-case.text-orange-400.text-xxs.font-semibold= t("required")
= f.email_field :email, autocomplete: false, required: true, class: "form-input mt-1 block w-full text-field focus:shadow-outline focus:border-green-300", placeholder: "richard@piedpiper.com"
# Or with the form builder
= f.label :email, required: true, class: "block text-xxs uppercase text-gray-500", required_class: "ml-2 normal-case text-orange-400 text-xxs font-semibold"
= f.email_field :email, autocomplete: false, required: true, class: "form-input mt-1 block w-full text-field focus:shadow-outline focus:border-green-300", placeholder: "richard@piedpiper.com"
@sowenjub
sowenjub / base.rb
Last active August 29, 2015 14:14 — forked from apneadiving/base.rb
class FormObjectBase
include ::ActiveModel::Validations
attr_reader :object, :params
def initialize(object)
@object = object
end
def assign(params)
$my-icons-spacing: 10px; // give some space to avoid little pixel size issues on resize
@import "my-icons/*.png";
$my-icons-sprite-dimensions: true;
@include all-my-icons-sprites;
// the fun part