Skip to content

Instantly share code, notes, and snippets.

View nadar71's full-sized avatar
🏠
Working from home

Simone Mapelli nadar71

🏠
Working from home
View GitHub Profile

FWIW: I (@Rondy) am not the author of the content presented here, which is an outline from Edmond Lau's book. I've just copy-pasted it from somewhere and saved as a personal gist, before it got popular on newsnews.ycombinator.com. I don't remember where exactly the original source is from and neither could find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

suspend fun fibonacci(): Flow<BigInteger> = flow {
var x = BigInteger.ZERO
var y = BigInteger.ONE
while (true) {
emit(x)
x = y.also {
y += x
}
}
}
@nadar71
nadar71 / callback_with_params.py
Created February 15, 2022 11:27
Callback example in Python, with parameters
def get_square(val):
"""The callback."""
return val ** 2
def caller(func, val):
return func(val)
caller(get_square, 5)
print caller(get_square, 5)
@nadar71
nadar71 / callback_js.html
Created February 15, 2022 11:17
Javascript callback samples, with parameters
<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<script>
function calculate(num1, num2, callbackFunction) {
return callbackFunction(num1, num2);
}
function calcProduct(num1, num2) {
@nadar71
nadar71 / callback_with_params.c
Last active February 15, 2022 11:13
C callback sample with parameters
/*
* This is a simple C program to demonstrate the usage of callbacks
* The callback function is in the same file as the calling code.
* The callback function can later be put into external library like
* e.g. a shared object to increase flexibility.
*
*/
#include <stdio.h>
#include <string.h>
@nadar71
nadar71 / callback_no_params.c
Created February 15, 2022 11:11
C callback sample without parameters
#include <stdio.h>
#include <stdlib.h>
/* The calling function takes a single callback as a parameter. */
void PrintTwoNumbers(int (*numberSource)(void)) {
int val1 = numberSource();
int val2 = numberSource();
printf("%d and %d\n", val1, val2);
}
@nadar71
nadar71 / MainSettingsActivity.kt
Created January 16, 2021 17:07
Open current app info
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.setData(Uri.parse("package:" + getString(R.string.app_package)));
startActivity(intent);
@nadar71
nadar71 / coroutines_exception
Created November 10, 2020 15:19
coroutines exception handling
private val exceptionHandler = CoroutineExceptionHandler { _, exception ->
LogHelper.log(TAG, "User Observer Exception: ${exception.stackTrace}", Log.ERROR)
}
private suspend fun userHasClientCodes(user : FirebaseUser, request: UsersRequest, token : String): String? =
withContext(Dispatchers.IO+ exceptionHandler) {
val response = CustomerAreaAPI.createUser(request, "Bearer ${token}")
if (response != null && response !is String) {
if (AppPreferences.firstTimeNotification == 0) {
AppPreferences.firstTimeNotification = 1
@nadar71
nadar71 / Util.kt
Last active October 25, 2020 15:04
* Take the Long milliseconds returned by the system and stored in Room, * and convert it to a nicely formatted string for display. * * EEEE - Display the long letter version of the weekday * MMM - Display the letter abbreviation of the nmotny * dd-yyyy - day in month and full year numerically * HH:mm - Hours and minutes in 24hr format
/**
* Take the Long milliseconds returned by the system and stored in Room,
* and convert it to a nicely formatted string for display.
*
* EEEE - Display the long letter version of the weekday
* MMM - Display the letter abbreviation of the nmotny
* dd-yyyy - day in month and full year numerically
* HH:mm - Hours and minutes in 24hr format
*/
@SuppressLint("SimpleDateFormat")
import android.view.View
import it.diceworld.dicehome.utility.OnSingleClickListener
fun View.setGone(){
this.visibility = View.GONE
}
fun View.setVisible(){
this.visibility = View.VISIBLE
}