Skip to content

Instantly share code, notes, and snippets.

Avatar

César Ferreira cesarferreira

View GitHub Profile
View http_request_protocol.dart
/// 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');
View insertUser.kt
// 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)
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@cesarferreira
cesarferreira / gist:a6e38f609306f429167060fbb1caf2f5
Created Jul 18, 2019 — forked from bessarabov/gist:674ea13c77fc8128f24b5e3f53b7f094
One-liner to generate data shown in post 'At what time of day does famous programmers work?' — https://ivan.bessarabov.com/blog/famous-programmers-work-time
View gist:a6e38f609306f429167060fbb1caf2f5
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); }'
View get-medium-stats.js
const totalTypes = {
VIEWS: 2,
READS: 3,
FANS: 5
};
const getTotal = tableColumn =>
[
...document.querySelectorAll(
`td:nth-child(${tableColumn}) > span.sortableTable-number`
View MyViewModel.kt
class MyViewModel: ViewModel() {
init {
viewModelScope.launch {
// Coroutine that will be canceled when the ViewModel is cleared.
}
}
}
View FriendsFragment.kt
class FriendsFragment : BaseFragment() {
override fun layoutId(): Int = R.layout.fragment_friends
private lateinit var friendsViewModel: FriendsViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
appComponent.inject(this)
View FriendsViewModel.kt
class FriendsViewModel @Inject constructor(
private val getFriendsUseCase: GetFriendsUseCase
) : BaseViewModel() {
sealed class FriendsState {
object Loading : FriendsState()
object Empty : FriendsState()
data class Success(val users: List<UserUiModel>) : FriendsState()
}
View GetFriendsUseCase.kt
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) {
You can’t perform that action at this time.