Skip to content

Instantly share code, notes, and snippets.

View matteo-grella's full-sized avatar
🔥
I enjoy programming my own inventions.

Matteo Grella matteo-grella

🔥
I enjoy programming my own inventions.
View GitHub Profile
package main
import (
"fmt"
"log"
"reflect"
"github.com/nlpodyssey/spago/ag"
"github.com/nlpodyssey/spago/gd"
"github.com/nlpodyssey/spago/gd/sgd"
@matteo-grella
matteo-grella / mypool.go
Created February 12, 2022 12:12
MyPool is a naive implementation of a pool, based on broadcast channel.
package mypool
// MyPool is a naive implementation of a pool, based on broadcast channel.
// You can use this pool in the same way you use sync.Pool.
type MyPool struct {
pool chan interface{}
// New optionally specifies a function to generate
// a value when Get would otherwise return nil.
New func() interface{}
@matteo-grella
matteo-grella / italian_linguistic_contraints.json
Created February 12, 2020 22:09
Italian Linguistic Constraints
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2011-2017 Matteo Grella <matteogrella@gmail.com> --
-- --
-- This work is licensed under a Creative Commons --
-- Attribution-ShareAlike 4.0 International License. --
-- --
-- This file contains a subset of the Italian Grammar expressed as a set --
-- of constraints, in line with WCDG formalism. The 243 constraints below --
-- are used in my most recent dependency parsing experiments which combine --
@matteo-grella
matteo-grella / deleteevictedpods.sh
Created December 4, 2019 23:42
Delete evicted pods
kubectl get po --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -
@matteo-grella
matteo-grella / blas.go
Created November 18, 2019 00:09 — forked from xoba/blas.go
how easy it is to use blas from go-lang
// see http://www.netlib.org/clapack/cblas/dgemv.c
package main
/*
#cgo LDFLAGS: -L/usr/lib/libblas -lblas
#include <stdlib.h>
extern void dgemv_(char* trans, int *m, int *n, double *alpha,
double *A, int *lda, double *x, int *incx, double *beta, double *y,
int *incy);
*/
@matteo-grella
matteo-grella / reverse.go
Last active October 17, 2019 17:59
Reverse string in Go
func reverse(lst []string) chan string {
ret := make(chan string)
go func() {
for i, _ := range lst {
ret <- lst[len(lst)-1-i]
}
close(ret)
}()
return ret
}
import com.kotlinnlp.simplednn.simplemath.ndarray.dense.DenseNDArray
fun List<DenseNDArray>.sumWithPrevAndNext(): List<DenseNDArray> = this.indices.map { i ->
val cur = this[i].copy()
if (i > 0) cur.assignSum(this[i - 1])
if (i < this.lastIndex) cur.assignSum(this[i + 1])
cur
}
fun List<DenseNDArray>.addBackwardOfSumWithPrevAndNext(gradients: List<DenseNDArray>) = this.indices.map { i ->
@matteo-grella
matteo-grella / Combinations.kt
Created May 18, 2019 12:31
Extension method that returns the combinations of the elements of a list
/**
* Returns the combinations of the elements in this list as a list of pairs.
*
* The returned list is empty if this collection contains less than two elements.
*
* @return the combinations of the elements
*/
fun <E>List<E>.combine(): List<Pair<E, E>> = this.foldIndexed(mutableListOf()) { i, acc, element ->
for (j in i + 1 until this.size) {
/**
* @param resource the path to the resource to load
*
* @return the content of the resource
*/
fun loadResource(resource: String): String =
try {
object {}.javaClass.getResource(resource).readText(Charsets.UTF_8)
} catch (all: Exception) {
throw RuntimeException("Failed to load resource=$resource!", all)
@matteo-grella
matteo-grella / RMQUtils.kt
Created May 13, 2019 13:02
Create a RabbitMQ Connection
import com.rabbitmq.client.Connection
import com.rabbitmq.client.ConnectionFactory
/**
* Create a RabbitMQ Connection.
*
* @param host the host
* @param port the port
* @param username the username (can be null)
* @param password the username (can be null)