Skip to content

Instantly share code, notes, and snippets.

View renaudcerrato's full-sized avatar

Renaud Cerrato renaudcerrato

View GitHub Profile
@renaudcerrato
renaudcerrato / SetAdapter.ps1
Created June 15, 2025 14:17
Powershell script to set NIC properties
#Requires -Modules NetAdapter
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Conditionally sets or displays a specified advanced property of a network adapter.
Filters adapters by keyword support. If no adapter name is given and a single
matching adapter is found, it's selected automatically. Otherwise, it prompts.
.DESCRIPTION
@renaudcerrato
renaudcerrato / Window.kt
Created June 6, 2025 06:32
Kotlin's Window flow operator
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
@renaudcerrato
renaudcerrato / dyndns.ovh
Last active December 26, 2021 13:33
POSIX Shell Script to Update ovh dyndns.
#!/bin/sh
error () {
echo "error: $1"
usage
}
usage () {
echo "usage: $0 -u <username> -p <password> -d <domain> -i <seconds> <subdomain>";
exit 1
@renaudcerrato
renaudcerrato / kotlin-stats.sh
Last active August 26, 2019 08:56
Kotlin vs Java Statistics
#!/usr/bin/env bash
KOTLIN=$(find . -name "*.kt" -exec cat {} \; | wc -l)
JAVA=$(find . -name "*.java" -exec cat {} \; | wc -l)
echo Kotlin: $KOTLIN lines \($(echo scale=2\; 100 \* $KOTLIN / \( $KOTLIN + $JAVA \) | bc -l)%\)
echo Java : $JAVA lines \($(echo scale=2\; 100 \* $JAVA / \( $KOTLIN + $JAVA \) | bc -l)%\)

Keybase proof

I hereby claim:

  • I am renaudcerrato on github.
  • I am renaudcerrato (https://keybase.io/renaudcerrato) on keybase.
  • I have a public key ASABbJwczM3qvM1NIE5Nv6myqn1Ou-ypR6p5XFAcsvCf-Qo

To claim this, I am signing this object:

@renaudcerrato
renaudcerrato / snippet.kt
Last active March 12, 2019 12:20
Kotlin Return with Labels
val list = listOf("Kotlin", "", "Java", "Groovy")
fun main() {
list.forEach {
if(it.isNullOrEmpty()) return@forEach // return with implicit label
println(it)
}
println("Done!")
}
@renaudcerrato
renaudcerrato / snippet.kt
Last active March 12, 2019 12:20
Kotlin Local Returns
// Kotlin's standard library extension
inline fun Array<String>.forEach(action: (String) -> Unit) {
for(str in this) {
action(str)
}
}
val list = listOf("Kotlin", "Java", "Groovy")
// a bare return statement in a lambda called from
@renaudcerrato
renaudcerrato / snippet.kt
Last active March 9, 2019 06:52
Kotlin Inline Function
inline fun greeter(action: () -> Unit) {
try {
println("Hello!")
action()
}finally{
println("Goodbye!")
}
}
greeter {
@renaudcerrato
renaudcerrato / snippet.kt
Created February 24, 2019 08:56
Kotlin Try/Catch expression
// the returned value is the last expression of the try or catch block
val a: Int? = try { parseInt(input) } catch (e: NumberFormatException) { null }
fun printNumber(reader: BufferedReader) {
val number = try {
parseInt(reader.readLine())
} catch (e: NumberFormatException) {
return
}
@renaudcerrato
renaudcerrato / snippet.kt
Last active March 9, 2019 06:20
Kotlin Enum
enum class Direction {
NORTH, SOUTH, WEST, EAST
}
enum class Color(val rgb: Int) {
RED(0xFF0000),
GREEN(0x00FF00),
BLUE(0x0000FF)
}