Skip to content

Instantly share code, notes, and snippets.

function xc {
bold=$(tput bold)
normal=$(tput sgr0)
xcode_proj=`find . -name "*.xc*" -d 1 | sort -r | head -1`
if [[ `echo -n $xcode_proj | wc -m` == 0 ]]
then
echo "No xcworkspace/xcodeproj file found in the current directory."
else
echo "Opening ${bold}\033[1;32m$xcode_proj"
open "$xcode_proj"
//
// OCXML.swift
// Created by Marco Arment on 9/23/24.
//
// Released into the public domain. Do whatever you'd like with this.
// No guarantees that it'll do anything, or do it correctly. Good luck!
//
import Foundation
@ricardopereira
ricardopereira / avd.sh
Created November 16, 2023 11:31 — forked from hidroh/avd.sh
Handy bash script to prompt for an Android virtual device (AVD) selection and launch it. Assuming that Android SDK has been set up and is in user PATH.
pushd ${ANDROID_HOME}/emulator
./emulator -list-avds | cat -n
printf "Select AVD: "
read index
avd=$(./emulator -list-avds | sed "${index}q;d")
echo "Selected $avd"
./emulator -netdelay none -netspeed full -avd $avd
popd
@ricardopereira
ricardopereira / grid-trainer.swift
Created August 1, 2022 13:32 — forked from swiftui-lab/grid-trainer.swift
A grid trainer for Grid views
// Author: SwiftUI-Lab (swiftui-lab.com)
// Description: this learning tool is designed to showcase the different
// Grid and GridRow view options, added in SwiftUI 2022. It is part of the
// blog article: https://swiftui-lab.com/eager-grids
//
import SwiftUI
import UniformTypeIdentifiers
// The root view of the application
struct ContentView: View {
@ricardopereira
ricardopereira / DownloadProgressLiveData.kt
Created February 18, 2022 16:18 — forked from FhdAlotaibi/DownloadProgressLiveData.kt
Observe Download manager progress using LiveData and Coroutine
data class DownloadItem(val bytesDownloadedSoFar: Long = -1, val totalSizeBytes: Long = -1, val status: Int)
class DownloadProgressLiveData(private val application: Application, private val requestId: Long) : LiveData<DownloadItem>(), CoroutineScope {
private val downloadManager by lazy {
application.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
}
private val job = Job()
@ricardopereira
ricardopereira / SubscriptionTests.swift
Created September 13, 2021 17:17
Using the SKTestSession in XCTest.
import XCTest
import StoreKitTest
@available(iOS 14.0, *)
class SubscriptionTests: XCTestCase {
private var session: SKTestSession!
private var subscriptionsController: SubscriptionsController!
override func setUpWithError() throws {
@ricardopereira
ricardopereira / LeakCheckTestCase.swift
Created August 10, 2021 08:28 — forked from aclima93/LeakCheckTestCase.swift
Automated detection of memory leaks in Unit Tests
class LeakCheckTestCase: XCTestCase {
private var excludedProperties = [String: Any]()
private var weakReferences = NSMapTable<NSString, AnyObject>.weakToWeakObjects()
// MARK: - SetUp
override func setUpWithError() throws {
try super.setUpWithError()
@ricardopereira
ricardopereira / BaseViewBindingFragment.java
Created November 12, 2020 17:47 — forked from killvetrov/BaseViewBindingFragment.java
Android View Binding: base class to reduce boilerplate in Java
public abstract class BaseViewBindingFragment extends Fragment {
private Field bindingField;
private Method inflate;
{
try {
for (Field declaredField : this.getClass().getDeclaredFields()) {
if (ViewBinding.class.isAssignableFrom(declaredField.getType())) {
bindingField = declaredField;
//
// PasscodeKeychain.swift
// Example
//
// Created by Ricardo Pereira on 23/12/2016.
// Copyright © 2016 RP. All rights reserved.
//
import Foundation
@ricardopereira
ricardopereira / Transaction.swift
Created July 31, 2020 14:48 — forked from IanKeen/Example_Complex.swift
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
import SwiftUI
import Combine
@propertyWrapper
@dynamicMemberLookup
public struct Transaction<Value>: DynamicProperty {
@State private var derived: Value
@Binding private var source: Value
fileprivate init(source: Binding<Value>) {