Skip to content

Instantly share code, notes, and snippets.

View alediaferia's full-sized avatar
🏢
Working from work

Alessandro Diaferia alediaferia

🏢
Working from work
View GitHub Profile
@alediaferia
alediaferia / proxy.conf.tpl
Last active July 5, 2020 12:58
The chisel proxy NGINX configuration
server {
# Italian public free dns taken from https://public-dns.info/nameserver/it.html
resolver 88.80.70.7;
listen $__PORT__$ default_server;
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'https://chisel.cloud';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-Chisel-Proxied-Url,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
@alediaferia
alediaferia / nginx.conf
Created July 5, 2020 10:15
Unprivileged nginx.conf configuration
worker_processes 4;
daemon off;
error_log /var/log/nginx/error.log warn;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
@alediaferia
alediaferia / .gitlab-ci.yml
Created December 8, 2019 17:37
GitLab CI example snippet for building and releasing images to Heroku
stages:
- build
- release
build_image:
only:
- master
image: registry.gitlab.com/majorhayden/container-buildah
stage: build
variables:

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 December 16, 2018 18:12
A working version of the test with LiveData
@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 December 16, 2018 10:25
A non-working test with LiveData
@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 December 16, 2018 10:23
A very simple example DAO
@Dao
interface PostDao {
@Query("SELECT * from posts")
fun getAll(): LiveData<List<Post>>
@Insert
fun insert(post: Post)
}
@alediaferia
alediaferia / LICENSE
Last active November 16, 2019 07:07
LiveData observer useful for unit testing
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 January 3, 2018 19:50
An array of country names in Go
var Countries = []string{
"Afghanistan",
"Albania",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antarctica",
"Antigua and Barbuda",
// 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)