Skip to content

Instantly share code, notes, and snippets.

@Runman44
Runman44 / authService.dart
Created July 10, 2020 14:52
Authentication Service for Firebase/Flutter in Dart
class AuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
Stream<User> get user {
return _auth.onAuthStateChanged.map(_userFromFirebaseUser);
}
User _userFromFirebaseUser(FirebaseUser user) {
return user != null ? User(id: user.uid, name: user.displayName, email: user.email) : null;
@Runman44
Runman44 / no_withContext.kt
Created May 3, 2020 15:08
No withContext
suspend fun refreshTitle() {
try {
// Make network request using a blocking call
val result = network.fetchNextTitle()
titleDao.insertTitle(Title(result))
} catch (cause: Throwable) {
// If anything throws an exception, inform the caller
throw TitleRefreshError("Unable to refresh title", cause)
}
}
@Runman44
Runman44 / withContext_yield.kt
Created May 3, 2020 15:07
withContext with yield
suspend fun refreshTitle() {
// interact with *blocking* network and IO calls from a coroutine
withContext(Dispatchers.IO) {
val result = try {
// Make network request using a blocking call
network.fetchNextTitle().execute()
} catch (cause: Throwable) {
// If the network throws an exception, inform the caller
throw TitleRefreshError("Unable to refresh title", cause)
}
@Runman44
Runman44 / withContext.kt
Created May 3, 2020 15:06
withContext example
suspend fun refreshTitle() {
// interact with *blocking* network and IO calls from a coroutine
withContext(Dispatchers.IO) {
val result = try {
// Make network request using a blocking call
network.fetchNextTitle().execute()
} catch (cause: Throwable) {
// If the network throws an exception, inform the caller
throw TitleRefreshError("Unable to refresh title", cause)
}
@Runman44
Runman44 / ndk_android.groovy
Created February 11, 2019 17:04
ndk_android
ndk {
abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
sealed class ScreenState3 {
object LoadingState : ScreenState3()
class ErrorState(val error: Throwable) : ScreenState3()
class SuccessState(val data: String) : ScreenState3()
}
fun main(args: Array<String>) {
val response3: ScreenState3 = ScreenState3.SuccessState("yay")
open class ScreenState2 {
object LoadingState : ScreenState2()
class ErrorState(val error: Throwable) : ScreenState2()
class SuccessState(val data: String) : ScreenState2()
}
fun main(args: Array<String>) {
val response2: ScreenState2 = ScreenState2.SuccessState("yay")
enum class ScreenState {
LOADING,
ERROR,
SUCCESS
}
class Response(val state: ScreenState, val data: String?, val error: Throwable?)
fun main(args: Array<String>) {
@Runman44
Runman44 / gist:f1f6530e150bc55be6a0b5ef61cab5b7
Created October 24, 2018 11:23
git_hook_prefix_commit_msg
#!/usr/bin/env python
import sys, re
from subprocess import check_output
commit_msg_filepath = sys.argv[1]
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip()
regex = '(STRY.\d+)'
if re.search(regex, branch):
issue = re.search(regex, branch).group()