Skip to content

Instantly share code, notes, and snippets.

View ContextExt.kt
/**
* Returns true when [Context] is unavailable or is about to become unavailable
*/
fun Context?.isDoomed(): Boolean = when (this) {
null -> true
is Application -> false
is Activity -> (this.isDestroyed or this.isFinishing)
else -> false
}
View callback-example.kt
fun test1(callback: (() -> Unit)? = null) {
callback?.let {
it()
}
}
fun test2(callback: () -> Unit?) {
callback()
}
View list-files-by-extension.sh
find . -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -n | grep -Ei '(java|kt|cpp)$'
@paulo-coutinho
paulo-coutinho / flutter-load-db.dart
Created Jul 14, 2020
Create a fresh or not database with Flutter
View flutter-load-db.dart
Future<Database> loadDatabase() async {
bool alwaysFreshDatabase = true;
if (alwaysFreshDatabase) {
var databasesPath = await getDatabasesPath();
var path = join(databasesPath, 'bible.db');
// delete existing if any
await deleteDatabase(path);
View git-clear-history.sh
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
View MemorySamples.cpp
#include <iostream>
#include <string>
#include <vector>
#include <memory>
void show_1(int value) {
std::cout << "show_1: " << &value << std::endl;
}
void show_2(int & value) {
@paulo-coutinho
paulo-coutinho / OkHttpUtils.java
Created Nov 19, 2018
OkHttp utility class to stop call by tag
View OkHttpUtils.java
package com.prsolucoes.android;
import android.text.TextUtils;
import okhttp3.Call;
import okhttp3.OkHttpClient;
public class OkHttpUtils {
public static void cancelCallWithTag(OkHttpClient client, String tag) {
@paulo-coutinho
paulo-coutinho / workaround-player.m
Created Sep 19, 2018
Workaround to enable audio session
View workaround-player.m
- (void)activateAudioSession
{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}
View xcode-clean.sh
#!/bin/sh
text_magenta=$(tput setaf 5)
text_bold=$(tput bold)
text_normal=$(tput sgr0)
archives_path=~/"Library/Developer/Xcode/Archives"
derived_data_path=~/"Library/Developer/Xcode/DerivedData"
simulator_data_path=~/"Library/Developer/CoreSimulator/Devices"
device_support_path=~/"Library/Developer/Xcode/iOS DeviceSupport"
@paulo-coutinho
paulo-coutinho / xcode-envs.txt
Created Jan 3, 2018
Xcode Environment Variables
View xcode-envs.txt
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
ALWAYS_SEARCH_USER_PATHS = NO
ALWAYS_USE_SEPARATE_HEADERMAPS = YES
APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer
APPLE_INTERNAL_DIR = /AppleInternal
APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation