Skip to content

Instantly share code, notes, and snippets.

🏢
Working from work

Alessandro Diaferia alediaferia

🏢
Working from work
Block or report user

Report or block alediaferia

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alediaferia
alediaferia / .gitlab-ci.yml
Created Dec 8, 2019
GitLab CI example snippet for building and releasing images to Heroku
View .gitlab-ci.yml
stages:
- build
- release
build_image:
only:
- master
image: registry.gitlab.com/majorhayden/container-buildah
stage: build
variables:
View keybase.md

Keybase proof

I hereby claim:

  • I am alediaferia on github.
  • I am alediaferia (https://keybase.io/alediaferia) on keybase.
  • I have a public key ASCgtkVIoLE2kGU0I9UJ_8KaGbDRQLm7OYdIhbDlr464hwo

To claim this, I am signing this object:

@alediaferia
alediaferia / PostDaoReadWriteTest.kt
Created Dec 16, 2018
A working version of the test with LiveData
View PostDaoReadWriteTest.kt
@RunWith(AndroidJUnit4::class)
class PostDaoReadWriteTest {
private lateinit var postDao: PostDao
private lateinit var db: TestDatabase
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
@Before
fun createDb() {
@alediaferia
alediaferia / PostDaoTest.kt
Last active Dec 16, 2018
A non-working test with LiveData
View PostDaoTest.kt
@RunWith(AndroidJUnit4::class)
class PostDaoReadWriteTest {
private lateinit var postDao: PostDao
private lateinit var db: TestDatabase
@Before
fun createDb() {
val context = ApplicationProvider.getApplicationContext<Context>()
db = Room.inMemoryDatabaseBuilder(
context, TestDatabase::class.java).build()
@alediaferia
alediaferia / PostDao.kt
Last active Dec 16, 2018
A very simple example DAO
View PostDao.kt
@Dao
interface PostDao {
@Query("SELECT * from posts")
fun getAll(): LiveData<List<Post>>
@Insert
fun insert(post: Post)
}
@alediaferia
alediaferia / LICENSE
Last active Nov 16, 2019
LiveData observer useful for unit testing
View LICENSE
Copyright 2019 Alessandro Diaferia
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
@alediaferia
alediaferia / countries.go
Created Jan 3, 2018
An array of country names in Go
View countries.go
var Countries = []string{
"Afghanistan",
"Albania",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua and Barbuda",
View levenshtein_distance.go
// This implementation takes advantage of the 2-columns
// approach as shown in
// https://en.wikipedia.org/wiki/Levenshtein_distance#Iterative_with_two_matrix_rows
//
// You are encouraged to use this function when simply
// interested in the levenshtein distance between 2 words.
func LevenshteinDistance(source, destination string) int {
vec1 := make([]int, len(destination) + 1)
vec2 := make([]int, len(destination) + 1)
@alediaferia
alediaferia / word_similarity.go
Last active Jan 3, 2018
A simple function to compute the similarity between 2 words
View word_similarity.go
import "math"
// similarity computes the similarity between
// 2 words. w1len and w2len are the lengths of the 2
// words for which to compute the similarity.
// ld is the levenshtein distance between the 2 words.
// It returns a value between 0 and 1 that identifies the similarity
// between the 2 words. 2 equal words will have a similarity of 1.
func similarity(w1Len, w2Len, ld int) float64 {
maxLen := math.Max(float64(w1Len), float64(w2Len))
@alediaferia
alediaferia / gogoa_howto.go
Created Dec 31, 2017
How to implement Gogoa
View gogoa_howto.go
package gogoa
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Cocoa
//#include "g_application.h"
import "C"
import "unsafe"
type Application struct {
ptr unsafe.Pointer
You can’t perform that action at this time.