Skip to content

Instantly share code, notes, and snippets.

@phimage
phimage / git-rm-hist
Last active February 10, 2023 13:38
Remove history before a commit hash
#!/bin/sh
hash="$1"
if [ -z "$hash" ]; then
echo "No hash argument supplied"
echo "usage: $0 <hash> (<first message>)"
exit 1
fi
message="$2"
if [ -z "$message" ]; then
@phimage
phimage / UIButton+onMenuActionTriggered.swift
Created March 2, 2021 13:42
Update menu of UIControl (UIButton, ...) on touch
extension UIControl {
/// Update the menu when the action is triggered,
/// when we use `menu` and optionnaly `showsMenuAsPrimaryAction`.
///
/// - Parameter menuHandler: the callback to modify the menu.
func onMenuActionTriggered(menuHandler: @escaping (UIMenu) -> UIMenu) {
self.addAction(UIAction(title: "", handler: { _ in
DispatchQueue.main.async { [weak self] in // if done before menu visible we have "while no context menu is visible. This won't do anything."
self?.contextMenuInteraction?.updateVisibleMenu(menuHandler)
@phimage
phimage / Ellipsis.swift
Last active February 12, 2021 07:34
Just animate ellipsis image
//
// ContentView.swift
// SymbolShaped
//
// Created by emarchand on 11/02/2021.
//
import SwiftUI
struct ContentView: View {
@phimage
phimage / uiappearance-selector.md
Created September 3, 2018 14:09 — forked from mattt/uiappearance-selector.md
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
@phimage
phimage / UIStackView+Rearrange.swift
Created August 19, 2018 22:24
Rearrange an UIStackView subviews using algorithm provided by closure
extension UIStackView {
public static let defaultRearrangeConfigure: ((UIStackView, Int) -> Void) = { configurableStackView, index in
configurableStackView.alignment = .fill
configurableStackView.distribution = .fillEqually
configurableStackView.axis = .horizontal
configurableStackView.autoresizesSubviews = true
}
public func rearrange(distribution: (Int) -> Bool, configure: ((UIStackView, Int) -> Void) = UIStackView.defaultRearrangeConfigure) {
@phimage
phimage / 4DPreferences.xml
Created May 3, 2018 08:08
4D Preferences for syntax coloration
<?xml version="1.0" encoding="UTF-8"?>
<preferences stamp="601">
<com.4d>
<general><automatisms licence_reminder_lasttime="-1" startup_mode="0"/><tabbing mode="2"/></general><structure pk_defaultName="ID"/>
<method_editor><options show_blocks_hilite="true" show_lists="false"/><general font_name="Monaco" font_size="14"/>
<back_color><color alpha="255" blue="53" green="43" red="40"/></back_color>
<syntax_style syntax="4D">
<syntax kind="plain_text"><color alpha="255" blue="251" green="255" red="253"/><style bold="false" italic="false" underline="false"/></syntax>
<syntax kind="commands"><color alpha="255" blue="202" green="175" red="7"/><style bold="true" italic="false" underline="true"/></syntax>
<syntax kind="keywords"><color alpha="255" blue="153" green="52" red="194"/><style bold="true" italic="false" underline="false"/></syntax>
@phimage
phimage / WEB GET VARIABLES AS OBJECT.4dm
Last active April 15, 2018 07:13
Transform `WEB GET VARIABLES` result into `C_OBJECT`
// Transform `WEB GET VARIABLES` result into `C_OBJECT`
//
// ex: `key=value&flag&multiplekey=value1&multiplekey=value2`
// -> `{ "key": "value", "flag": "", "multiplekey": [ "value1", "value2" ] }`
//
// - parameter objectify: If `True` variable key containing `.`
// will create sub objects.
// ex: `object.first=value&object.second=1`
// -> `{ "object": { "first": "value", "second": "1" } }`
//
@phimage
phimage / gist:f354c38f19a6cf4725e83e5bcd4292e3
Last active March 19, 2018 09:11
recursively get subviews
func flatten<T>(value: T, childrenClosure: (T) -> [T]) -> [T] {
var result: [T] = childrenClosure(value)
result = result.flatMap { flatten(value: $0, childrenClosure: childrenClosure) }
return [value] + result
}
// recursively get subviews
let views = flatten(value: view) { $0.subviews }
@phimage
phimage / MoyaRemoveReactive.sh
Created February 13, 2018 10:27
Remove Reactive frameworks when building Moya with Carthage
## Sources
rm -Rf Carthage/Checkouts/Reactive*
rm -Rf Carthage/Checkouts/Rx*
## Build artifact
rm -Rf Carthage/Build/Reactive*
rm -Rf Carthage/Build/Rx*
## Build scheme
rm -Rf Carthage/Checkouts/Moya/Moya.xcodeproj/xcshareddata/xcschemes/Reactive*
// Generated by Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
#pragma clang diagnostic push
#if defined(__has_include) && __has_include(<swift/objc-prologue.h>)
# include <swift/objc-prologue.h>
#endif
#pragma clang diagnostic ignored "-Wauto-import"
#include <objc/NSObject.h>
#include <stdint.h>