Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ricardopereira's full-sized avatar
🏠
Working from home

Ricardo Pereira ricardopereira

🏠
Working from home
View GitHub Profile
@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>) {
Test Case '-[Ably_iOS_Tests.RestClientChannel publish__with_a_Message_object__publishes_the_message_and_invokes_callback_with_success]' started.
2020-07-09 14:46:17.273356+0100 xctest[31356:914686] DEBUG: (ARTAuth.m:163) RS:0x7fd39c9411a0 validating <ARTClientOptions: 0x7fd39c92d7f0> -
key: _tmp__nL2MA.1KbX9A:ooIOdVMRWxMziqOk;
token: (null);
authUrl: (null);
authMethod: GET;
hasAuthCallback: 0;
clientId: (null);
2020-07-09 14:46:17.280911+0100 xctest[31356:914686] DEBUG: (ARTAuth.m:169) RS:0x7fd39c9411a0 setting up auth method Basic (anonymous)
2020-07-09 14:46:17.281595+0100 xctest[31356:914686] DEBUG: (ARTRestChannel.m:129) RS:0x7fd39a7f2010 instantiating under 'test-5-CECA5948-5BF4-4FAC-8518-D7CBC2993F22-31356-00004E247C318640'
import SwiftUI
import PlaygroundSupport
// constants
let cardWidth: CGFloat = 343
let cardHeight: CGFloat = 212
let spacing = 36
let animation = Animation.spring()
let cardColors = [
Color(UIColor.systemRed),