Skip to content

Instantly share code, notes, and snippets.

@apgapg
apgapg / logging_interceptor.dart
Created April 9, 2020 05:37
Logging interceptor for dio, flutter
import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
/// [LoggingInterceptor] is used to print logs during network requests.
/// It's better to add [LoggingInterceptor] to the tail of the interceptor queue,
/// otherwise the changes made in the interceptor behind A will not be printed out.
/// This is because the execution of interceptors is in the order of addition.
class LoggingInterceptor extends Interceptor {
extension DateTimeX<T extends DateTime> on T {
DateTime copyWith({
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int microsecond,
@aklinkert
aklinkert / check-git-uncommitted-changes.sh
Last active July 19, 2022 08:52
Bash script to recursively check uncommitted changes in a directory tree.
#!/usr/bin/env bash
cwd="$(pwd)"
find . -print0 -type d | while IFS= read -r -d '' file; do
if [ ! -d "${file}/.git" ]; then
continue
fi
cd "${file}"
if [[ -n $(git status -s) ]]; then
@csarron
csarron / scrcpy_shortcut.md
Created April 20, 2018 02:08
Scrcpy Shortcuts

Scrcpy Shortcuts

Action Shortcut
switch fullscreen mode Ctrl+f
resize window to 1:1 (pixel-perfect) Ctrl+g
resize window to remove black borders Ctrl+x | Double-click¹
click on HOME Ctrl+h | Middle-click
click on BACK Ctrl+b | Right-click²
click on APP_SWITCH Ctrl+m
@seanf
seanf / process.kt
Created August 23, 2017 02:12
Execute process from Kotlin
import java.lang.ProcessBuilder.Redirect
import java.util.concurrent.TimeUnit
fun String.runCommand(workingDir: File? = null) {
val process = ProcessBuilder(*split(" ").toTypedArray())
.directory(workingDir)
.redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT)
.start()
if (!process.waitFor(10, TimeUnit.SECONDS)) {
@ericksli
ericksli / TimberJava.xml
Last active February 11, 2021 18:19
Timber Android Studio live template for Java and Kotlin #kotlin #android
<templateSet group="TimberJava">
<template name="timd" value="timber.log.Timber.d(&quot;$METHOD_NAME$: $content$&quot;);" description="Timber.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="time" value="timber.log.Timber.e($exception$, &quot;$METHOD_NAME$: $content$&quot;);" description="Timber.e(Exception, String)" toReformat="true" toShortenFQNames="true">
<variable name="exception" expression="" defaultValue="e" alwaysStopAt="true" />
@patloew
patloew / RealmResultsObservable.java
Last active September 27, 2017 15:22
RealmResultsObservable
/* Copyright 2016 Patrick Löwenstein
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@knowbody
knowbody / RNfontWeights.js
Created July 14, 2016 13:42
React Native Font Weight Cheatsheet iOS
{ fontWeight: '100' }, // Thin
{ fontWeight: '200' }, // Ultra Light
{ fontWeight: '300' }, // Light
{ fontWeight: '400' }, // Regular
{ fontWeight: '500' }, // Medium
{ fontWeight: '600' }, // Semibold
{ fontWeight: '700' }, // Bold
{ fontWeight: '800' }, // Heavy
{ fontWeight: '900' }, // Black

Using Kotlin in Android projects

What is Kotlin?

Kotlin is a programming language backed by JetBrains, the company that develops IntelliJ IDEA, which is the backend of Android Studio. After five years of development, version 1.0 was released in February, 2016. Kotlin compiles to JVM bytecode that is fully compatible with the Android platform. The developers even pay special attention to it by providing libraries (for example Anko), tooling and more.

It is a language designed for interoperability with Java code, which allows for a gradual migration from Java to Kotlin. The tooling is great and aids usability much. Additionally, picking up the language is very easy if you already know Java, since the syntax and concepts are similar, while still providing a lot of value for developers held back by the bad Java support on Android. Most developers are currently limited to Java 7 or even Java 6 and it will take a long time before we'll be able to properly use features like lambda expressions to make code mo

@henriquemenezes
henriquemenezes / android-generate-keystores.md
Last active April 6, 2024 13:37
Android: Generate Release/Debug Keystores

Android: Generate Release/Debug Keystores

Generate Keystores

Debug Keystore

$ keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "C=US, O=Android, CN=Android Debug"