Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
Fluuuttering

Sergi Martínez sergiandreplace

:shipit:
Fluuuttering
View GitHub Profile
@sergiandreplace
sergiandreplace / TestingTimeAndDate.kt
Created Jan 13, 2021
Tests to play with the Time & Date Java 8 API
View TestingTimeAndDate.kt
import org.junit.Test
import java.time.*
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle
import java.time.temporal.ChronoField
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalAdjusters
import java.util.*
import kotlin.time.days
import kotlin.time.minutes
@sergiandreplace
sergiandreplace / join.sh
Last active Jul 4, 2020
Join US medicine tables
View join.sh
xsv join --no-case PRODUCTNDC product.txt PRODUCTNDC package.txt -d '\t' \
|xsv select NDCPACKAGECODE,PROPRIETARYNAME,PACKAGEDESCRIPTION,DOSAGEFORMNAME \
|xsv sample 10 \
|xsv table
View update medicines.sql
drop table if exists medicines_import;
CREATE TABLE medicines_import (
country text NOT NULL,
code text NOT NULL,
name text NOT NULL,
quantity int4 NOT NULL,
unit text NOT NULL,
CONSTRAINT medicines_pkey PRIMARY KEY (code, country)
);
View CnDetectorProcessor.kt
class CnDetectorProcessor(private val context: Context, private val onCnDetected: ((cn: String, checksum: String) -> Unit)) :
Detector.Processor<TextBlock?> {
private val pattern = Pattern.compile("^C?\\.?N?\\.? ?(\\d\\d\\d\\d\\d\\d)\\.(\\d) ?[0O]?\$")
private var detected = false
override fun release() {}
override fun receiveDetections(detections: Detections<TextBlock?>) {
detections.detectedItems.forEach { _, item ->
if (detected) return
@sergiandreplace
sergiandreplace / OverlayView.kt
Created Mar 11, 2020
A semitransparent view with a rounded corner hole in it
View OverlayView.kt
class OverlayWithHoleImageView(context: Context?, attrs: AttributeSet?) : androidx.appcompat.widget.AppCompatImageView(context, attrs) {
private var rect: RectF? = null
private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.parseColor("#a8000000")
style = Paint.Style.FILL
}
private val addMode = PorterDuffXfermode(PorterDuff.Mode.ADD)
private val clearMode = PorterDuffXfermode(PorterDuff.Mode.CLEAR)
private val radius = 40.dp
private val margin = 32.dp
View cyf_ecommerce_queries_exercise.sql
select name, address from customers where country = 'United States'
select * from customers order by name
/* Retrieve all the products which cost more than 100 */
select * from products where unit_price > 100
/* Retrieve all the products whose name contains the word socks */
View shameshameshame.js
var fs = require('fs');
class LineMatcher {
constructor(regex) {
this.regex = regex
}
matches(line) {
return this.regex.test(line)
}
View index.js
var a = Math.cos(Math.sin(((4 + 3) * 3)))
const PI = 3.14159
const GRAVITY = 9.8
// function concatenate(array) {
// let a = ""
// for (let i = 0; i < array.length; i++) {
// const element=array[i]
// a += element
// }
// return a
@sergiandreplace
sergiandreplace / CatalanDateFormatTest.kt
Last active Aug 25, 2019
A test to check if standalone month formatting for catalan works correctly
View CatalanDateFormatTest.kt
package com.sergiandreplace.localization
import org.junit.Test
import org.threeten.bp.LocalDate
import org.threeten.bp.Month
import org.threeten.bp.format.DateTimeFormatter
import java.util.Locale
import org.junit.Assert.assertEquals
class CatalanDateFormatTest {
@sergiandreplace
sergiandreplace / RecyclerViewAdapter.kt
Created Aug 15, 2019
AS File extension for RecyclerView adapters
View RecyclerViewAdapter.kt
#set($ModelName = $Model.replace("ViewModel",""))
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
class ${NAME}: RecyclerView.Adapter<${ModelName}ViewHolder>() {