Table of Contents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetFriendsUseCase( | |
private val friendsRepository: FriendsRepository | |
) : BaseUseCase<List<User>, GetFriendsUseCase.Params>() { | |
override suspend fun run(params: Params): Either<Failure, List<User>> { | |
return try { | |
val friends = friendsRepository.getFriends(params.maxNumberOfFriends) | |
Either.Right(friends) | |
} catch (exp: Exception) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cesarferreira.asynctaskcallback; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.widget.Toast; | |
public class MainActivity extends Activity { | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// HttpMethod: | |
/// リクエストのメソッドを定義 | |
/// Enum は Swift っぽくかける Util を使用 | |
class HttpMethod extends Enum<String> { | |
const HttpMethod(String val): super(val); | |
static const HttpMethod GET = const HttpMethod('GET'); | |
static const HttpMethod POST = const HttpMethod('POST'); | |
static const HttpMethod PUT = const HttpMethod('PUT'); | |
static const HttpMethod DELETE = const HttpMethod('DELETE'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.work.Worker | |
object AndroidWorkerInjection { | |
fun inject(worker: Worker) { | |
checkNotNull(worker, { "worker" }) | |
val application = worker.applicationContext | |
if (application !is HasWorkerInjector) { | |
throw RuntimeException("${application.javaClass.canonicalName} does not implement ${HasWorkerInjector::class.java.canonicalName}") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tasks.whenTaskAdded { task -> | |
if (task.name.equals("lint")) { | |
task.enabled = false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function createUser(user) { | |
// user.password = bcryptPassword(user.password) | |
// const userSaved = db.insert(user); | |
// generateConfirmationEmail(user) | |
// } | |
// | |
// | |
// function generateConfirmationEmail(user) { | |
// const key = `${md5(user.email)}.${Random.UUID()}` | |
// db.insertEmailConfirmation(user, key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git log --author="Linus Torvalds" --date=iso | perl -nalE 'if (/^Date:\s+[\d-]{10}\s(\d{2})/) { say $1+0 }' | sort | uniq -c|perl -MList::Util=max -nalE '$h{$F[1]} = $F[0]; }{ $m = max values %h; foreach (0..23) { $h{$_} = 0 if not exists $h{$_} } foreach (sort {$a <=> $b } keys %h) { say sprintf "%02d - %4d %s", $_, $h{$_}, "*"x ($h{$_} / $m * 50); }' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(NSInteger i = 0; i < 10; i++) { | |
// enqueue operation in queue | |
dispatch_async(queue, ^{ | |
// create semaphore | |
dispatch_semaphore_t sema = dispatch_semaphore_create(0); | |
// do something async, I do use another dispatch_queue for example | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ | |
// wrap in autoreleasepool to release memory upon completion | |
// in your case wrap the resultBlock in autoreleasepool |