Skip to content

Instantly share code, notes, and snippets.

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

Alberto Ballano aballano

🏠
Working from home
View GitHub Profile
public class UriUtil {
private final Context context;
private static final byte[] GIF89A_HEADER = {0x47, 0x49, 0x46, 0x38, 0x39, 0x61};
@Inject
public UriUtil(Context context) {
this.context = context;
}
public boolean isGif(Uri input) {
@aballano
aballano / Dependencies.kt
Last active March 2, 2018 20:59
Common dependencies
object Versions {
val kotlin = "1.2.21"
val appCompat = "27.0.2"
val constraintLayout = "1.0.2"
val kodein: String = "4.1.0"
val knex: String = "1.0"
val assertk: String = "0.9"
val mockitoKotlin: String = "1.5.0"
val koinAndroid: String = "0.8.2"
}
@aballano
aballano / ThenRx.kt
Created November 16, 2018 09:09
Mockito & RxJava extensions to facilitate mocking
@JvmName("thenErrorObservable")
fun <T> OngoingStubbing<Observable<T>>.thenError(throwable: Throwable) {
thenReturn(Observable.error(throwable))
}
fun OngoingStubbing<Completable>.thenComplete() {
thenReturn(Completable.complete())
}
@JvmName("thenErrorCompletable")
@aballano
aballano / utils.kt
Created May 4, 2020 16:59
Temporary workaround function to flatten an IO of Either
class IOException(val error: Any?) : Exception()
/**
* Flattens this IO's Either into IO itself, wrapping the untyped-Left side on a custom exception.
*
* Note: This is a workaround until IO<E, A> is available
*/
fun <A, B> IO<Either<A, B>>.flattenEither(): IO<B> =
this.flatMap {
it.fold(ifLeft = {
@aballano
aballano / Ender 3 - Parallel heating - Start G-code
Last active August 18, 2020 14:09
Small modification for the Cura start g-code for Ender 3 in order to start preheating both the hotend and the bed at the same time.
; Ender 3 Custom Start G-code
M140 S{material_bed_temperature} ; start preheating the bed WITHOUT wait to what is set in Cura
M104 S{material_print_temperature} T0 ; start preheating hotend WITHOUT wait to what is set in Cura
G92 E0 ; Reset Extruder
G28 ; Home all axes
M190 S{material_bed_temperature} ; start heating the bed to what is set in Cura and WAIT
M109 S{material_print_temperature} T0 ; start heating hotend to what is set in Cura and WAIT
; ALL BY DEFAULT BELOW THIS
G1 Z2.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed
G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position
@aballano
aballano / collector_controller.cs
Last active March 26, 2024 00:12
Space Engineers script to handle all Collectors' automatic on/off switch for a given Ice threshold is reached
// Define the amount of ice to trigger the collector deactivation
const int iceThreshold = 100000;
// Quick-access variables to avoid reinstantiation
IMyGridTerminalSystem grid;
List<IMyCollector> collectors;
List<IMyTerminalBlock> containers;
public Program()
{