Skip to content

Instantly share code, notes, and snippets.

@MaikelVeen
MaikelVeen / retry.go
Created March 6, 2022 12:15
The Retry Pattern in Go
type Effector func(context.Context) (string, error)
func Retry(effector Effector, retries int, delay time.Duration) Effector {
return func(ctx context.Context) (string, error) {
for r := 0; ; r++ {
response, err := effector(ctx)
if err == nil || r >= retries {
// Return when there is no error or the maximum amount
// of retries is reached.
return response, err
@techyourchance
techyourchance / MyPermission.java
Last active January 11, 2022 08:01
Abstraction for clean management of runtime permissions in Android applications
public enum MyPermission {
// declare runtime permissions specific to your app here (don't keep unused ones)
READ_PHONE_STATE(Manifest.permission.READ_PHONE_STATE),
FINE_LOCATION(Manifest.permission.ACCESS_FINE_LOCATION);
public static MyPermission fromAndroidPermission(String androidPermission) {
for (MyPermission permission : MyPermission.values()) {
if (permission.getAndroidPermission().equals(androidPermission)) {
return permission;
}
@faruktoptas
faruktoptas / debounce.kt
Created March 5, 2020 06:28
Kotlin coroutine debounce for EditText
fun <T> debounce(
waitMs: Long = 300L,
scope: CoroutineScope,
destinationFunction: (T) -> Unit
): (T) -> Unit {
var debounceJob: Job? = null
return { param: T ->
debounceJob?.cancel()
debounceJob = scope.launch {
delay(waitMs)
@marcorichetta
marcorichetta / postgresql-manjaro.md
Last active June 2, 2024 19:31
Install PostgreSQL on Manjaro and set it up for Django
@nickbutcher
nickbutcher / IconView.kt
Last active July 30, 2023 22:05
A prototype implementation of a shadow effect inspired by the Google Play Games app (https://play.google.com/store/apps/details?id=com.google.android.play.games).
/*
* Copyright 2017 Google Inc.
*
* 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@nikhita
nikhita / update-golang.md
Last active May 31, 2024 12:57
How to update the Go version

How to update the Go version

System: Debian/Ubuntu/Fedora. Might work for others as well.

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@matthewjberger
matthewjberger / instructions.md
Last active June 1, 2024 16:08
Install a nerd font on ubuntu

1.) Download a Nerd Font

2.) Unzip and copy to ~/.fonts

3.) Run the command fc-cache -fv to manually rebuild the font cache

@gauravbarthwal
gauravbarthwal / Multi-Part zip extraction in Ubuntu.txt
Last active May 8, 2024 07:47
How to extract multi-part .zip, .z01, .z02 files in ubuntu
Download/Copy all related *.zip files in one directory.
Open terminal and change to that directory which has all zip files.
Enter command zip -s- FILE_NAME.zip -O COMBINED_FILE.zip
Enter unzip COMBINED_FILE.zip
@teocci
teocci / AwesomeCourses.md
Last active February 14, 2024 07:08
List of awesome university courses for learning Computer Science!

Awesome Courses Awesome

Introduction

There is a lot of hidden treasure lying within university pages scattered across the internet. This list is an attempt to bring to light those awesome courses which make their high-quality material i.e. assignments, lectures, notes, readings & examinations available online for free.

Table of Contents

@diegoy
diegoy / MaskWatcher.java
Last active November 22, 2021 08:41
Apply masks to Android's Edit text adding this TextWatcher
/*
MIT License
Copyright (c) 2016 Diego Yasuhiko Kurisaki
*/
/* Example:
mEmailView.addTextChangedListener(new MaskWatcher("###-##"));
*/
import android.text.Editable;