Skip to content

Instantly share code, notes, and snippets.

View mac-cain13's full-sized avatar

Mathijs Kadijk mac-cain13

View GitHub Profile
@mac-cain13
mac-cain13 / Readme.md
Last active July 21, 2020 20:22
SwiftUI - ScrollViewSpy

ScrollViewLongPressSpy

Unleash the power of UIScrollView when just using SwiftUI ScrollView.

What is it?

A dummy "spy" view you can add inside your ScrollView that will attach a UILongPressGestureRecognizer to it and gives you a binding to the point where the finger is in the direct superview of the spy.

Why do I need it?

SwiftUI ScrollView is getting better every release, but currently (iOS 14) you can't add extra gesture recognizers. This is often needed for more complex interactions, this little spy gets that job done.

Is this the recommended way to add complex ScrollView behaviour?

@mac-cain13
mac-cain13 / AccessibleHStack.swift
Created July 9, 2020 07:19
SwiftUI - AccessibleHStack
//
// AccessibleHStack.swift
//
// Created by Mathijs Kadijk on 08/07/2020.
//
import SwiftUI
/// HStack that will switch to a VStack when the horizontal size class is compact and the content size category is set to an accessibility size option
struct AccessibleHStack<Content>: View where Content: View {
@mbuchetics
mbuchetics / json.swift
Created June 30, 2017 09:28 — forked from reckenrode/json.swift
Decoding arbitrary JSON with the new Decoder in Swift 4
enum JSON: Decodable {
case bool(Bool)
case double(Double)
case string(String)
indirect case array([JSON])
indirect case dictionary([String: JSON])
init(from decoder: Decoder) throws {
if let container = try? decoder.container(keyedBy: JSONCodingKeys.self) {
self = JSON(from: container)
@rponte
rponte / get-latest-tag-on-git.sh
Last active October 17, 2024 20:03
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@raphaelhanneken
raphaelhanneken / NSImageExtensions.swift
Last active August 24, 2023 01:04
NSImage extensions for easy resizing, cropping and saving png images.
//
// NSImageExtensions.swift
//
import Cocoa
extension NSImage {
/// The height of the image.
var height: CGFloat {

Convert iWork to Office mapactions

Automatically convert Pages and/or Keynote files added to a certain folder into Word and/or Powerpoint files. Just throw in the iWork files and this scripts will convert them into Office files in the same folder. The iWork versions will be moved to the trash.

Setup

  1. Copy the two AppleScript files to ~/Library/Workflows/Applications/Folder Actions
  2. Create a conversion folder where you'll put the files you want to convert
  3. Right click the folder, choose configure folder actions, check the "Enable folder actions" checkbox and attach the pages-to-word.scpt and/or keynote-to-powerpoint.scpt to your folder
@mac-cain13
mac-cain13 / Readme.md
Last active August 29, 2015 14:11
Automatically copy all PNG assets to the correct Android drawable folder when exporting from for example Sketch.

Android assets folder action

Automatically copy all PNG assets to the correct Android drawable folder. Very helpful when exporting assets with @?x-suffix from, for example, Sketch and putting them into the correct folder without human interaction.

Setup

  1. Copy the AppleScript file to ~/Library/Workflows/Applications/Folder Actions
  2. Create a export folder where you'll put all exported PNGs
  3. Right click the folder, choose configure folder actions, check the "Enable folder actions" checkbox and attach the android_assets.scpt to your folder
  4. Open the terminal and create a symbolic link by typing ln -s /path/to/android-project/app/src/main/res /path/to/export-folder-you-just-created
@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
@steveliles
steveliles / Foreground.java
Created April 20, 2014 15:30
Class for detecting and eventing the foreground/background state of an Android app - API-level 14+
package com.sjl.util;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import java.util.List;
@romaonthego
romaonthego / htmltest.m
Created September 23, 2013 16:08
UITextView with HTML text (iOS 7)
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] init];
textView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:textView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />";