Skip to content

Instantly share code, notes, and snippets.

Avatar

Uberto Barbini uberto

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am uberto on github.
  • I am ramtop (https://keybase.io/ramtop) on keybase.
  • I have a public key ASCJlFfUeGLy4B_A_nG22PQVS_HGmwdlFftKuJCycbZAmgo

To claim this, I am signing this object:

View kotlin-java-round.kt
import java.lang.Math.round as jround
import kotlin.math.round
fun main() {
val r = round(4.5) + round(9.5)
println("kotlin round 4.5+9.5 $r")
val r2 = round(5.5) + round(9.5)
View gist:a68a00a2290a520f21dfc322bc74e16e
import java.lang.Math.round as jround
import kotlin.math.round
fun main() {
val r = round(4.5) + round(9.5)
println("kotlin round 4.5+9.5 $r")
val r2 = round(5.5) + round(9.5)
@uberto
uberto / Factory.java
Created Dec 2, 2018
Create and export anonymous classes
View Factory.java
package com.gamasoft.memoryReferences;
import java.util.Observable;
public class Factory {
public Runnable createRunnable() {
return new Runnable() {
@Override
@uberto
uberto / delegation.kt
Created May 12, 2018
Multiple Inheritance via Delegation in Kotlin
View delegation.kt
package com.gamasoft.delegation
import assertk.assert
import assertk.assertions.isEqualTo
import org.junit.Test
//https://kotlinlang.org/docs/reference/delegation.html
interface Printer {
fun print(msg: String)
View board.py
def place_stone(self, player, point):
assert self.is_on_grid(point)
assert self._grid.get(point) is None
adjacent_same_color = []
adjacent_opposite_color = []
liberties = []
# First, we examine direct neighbors of this point.
for neighbor in point.neighbors():
if not self.is_on_grid(neighbor):
View Board.kt
fun placeStone(player: Player, point: Point) {
assert(isOnTheGrid(point))
assert(isFree(point))
//0. Examine the adjacent points.
val adjacentSameColor = mutableSetOf<GoString>()
val adjacentOppositeColor = mutableSetOf<GoString>()
val liberties = mutableSetOf<Point>()
for (neighbor in point.neighbors()) {
View gist:1d51d648d91a895b35fbb279d830c5da
Python
def remove_string(self, string):
for point in string.stones:
# Removing a string can create liberties for other strings.
for neighbor in self.neighbor_table[point]:
neighbor_string = self._grid.get(neighbor)
if neighbor_string is None:
continue
if neighbor_string is not string:
@uberto
uberto / Main.java
Created Aug 13, 2017
Use of Owner property
View Main.java
public static void main(String[] args){
ServerConfig config = ConfigFactory.create(ServerConfig.class);
List<Calculation> routes = Calculations.getAllCalculations(config.users());
WebServer.start(config.port(), routes);
}
@uberto
uberto / ServerConfig.java
Created Aug 13, 2017
Owner configuration interface
View ServerConfig.java
import org.aeonbits.owner.Config;
import org.aeonbits.owner.Config.Sources;
import java.util.List;
/**
* Keeps the configuration values for the server
*/
@Sources({ "file:config.properties" })
public interface ServerConfig extends Config {