Skip to content

Instantly share code, notes, and snippets.

View marcouberti's full-sized avatar

Marco Uberti marcouberti

  • Bending Spoons
  • Milan, Italy
View GitHub Profile
@marcouberti
marcouberti / kotlin_channels.kt
Created February 12, 2020 14:55
Kotlin Channel with buffer and natural batching
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.channels.*
fun main() = runBlocking<Unit> {
// create a Channel with a buffer of size 20
// this means that until 20 the send() are not suspending waiting for a receive()
val channel = Channel<String>(20)
@marcouberti
marcouberti / BinaryOperationsAndBitmasks.java
Created October 2, 2018 11:33
binary operators and bit masks in Java
public class BinaryOperationsAndBitmasks {
public static void main(String[] args) {
new BinaryOperationsAndBitmasks().bitsOperations();
}
/**
* Basic bitmap operations
*/
private void bitsOperations() {
@marcouberti
marcouberti / gradient_descent.js
Last active February 13, 2017 18:35
Simple Gradient Descent example in JS
/*
Our function f(x)
*/
function f(x) {
return x*x +5;
}
/*
The derivative df/dx of our function f(x)
*/
@marcouberti
marcouberti / android-mapping-file.gradle
Last active February 16, 2017 16:41
Copy and rename mapping.txt file if minify is enable
android {
applicationVariants.all { variant ->
def versionCode = android.defaultConfig.versionCode
def versionName = android.defaultConfig.versionName
def appendToFileName = versionName + "-build-" + versionCode
// copy and rename mapping.txt file if in minify is enable
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast{
copy {
@marcouberti
marcouberti / mock_android_context.java
Last active May 2, 2024 11:43
Mock Android Context using Mockito
import org.mockito.Mock;
import static org.mockito.Mockito.when;
@Mock
private Context mockApplicationContext;
@Mock
private Resources mockContextResources;
@Mock
private SharedPreferences mockSharedPreferences;
@marcouberti
marcouberti / bits_converter.py
Created December 29, 2016 17:04
Find LSB and MSB bit in Python
def bits_converter(x):
index = 0
bits = ""
while x is not 0:
bits += str(x & 1)
x = x >> 1
index+=1
return bits[::-1]