Skip to content

Instantly share code, notes, and snippets.

View sergiandreplace's full-sized avatar
:shipit:
Fluuuttering

Sergi Martínez sergiandreplace

:shipit:
Fluuuttering
View GitHub Profile
@sergiandreplace
sergiandreplace / pre-commit.sh
Created March 21, 2018 11:54
Pre-commit script for git. To save without extension
#!/bin/sh
local_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ ! "$local_branch" == feature* ]]
then
echo 'Failed to push. Branch name should start by feature/'
exit 1
fi
if [ "${#local_branch}" -ge 38 ]
then
echo 'Failed to push. Branch name could not be longer than 30 characters'
@sergiandreplace
sergiandreplace / bash
Created March 28, 2018 11:41
find wrong urls
for URL in `cat urls`; do curl -m 10 -s -X GET -I $1 "$URL" | grep HTTP/1.1 | (awk {'printf $2 '}; echo " $URL")| grep "^[^2]"; done
@sergiandreplace
sergiandreplace / styles.xml
Created August 11, 2019 16:48
Styling an inputLayout
<style name="Form.Field.EditText"
parent="@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox.Dense">
<item name="android:paddingTop">8dp</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:paddingRight">16dp</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
</style>
@sergiandreplace
sergiandreplace / RecyclerViewAdapter.kt
Created August 15, 2019 09:59
AS File extension for RecyclerView adapters
#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>() {
@sergiandreplace
sergiandreplace / CatalanDateFormatTest.kt
Last active August 25, 2019 18:30
A test to check if standalone month formatting for catalan works correctly
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 {
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
var fs = require('fs');
class LineMatcher {
constructor(regex) {
this.regex = regex
}
matches(line) {
return this.regex.test(line)
}
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 */
@sergiandreplace
sergiandreplace / OverlayView.kt
Created March 11, 2020 18:40
A semitransparent view with a rounded corner hole in it
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
@sergiandreplace
sergiandreplace / CnDetectorProcessor.kt
Last active March 18, 2020 09:27
CnDetectorProcessor
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