Skip to content

Instantly share code, notes, and snippets.

@StrumentiResistenti
StrumentiResistenti / EAN.scala
Last active January 20, 2019 23:23
EAN checkdigit calculation
object EAN {
def eanChecksum(in: String, eanLength: Int) = {
// fetch some elements from a sequence
def getIf(in: Seq[Int], condition: (Int) => Boolean) =
List.range(0, in.size).filter(condition).map(i => in(i))
// fetch odd or even elements from a sequence
def getOdd(in: Seq[Int]) = getIf(in, _%2!=0)
def getEven(in: Seq[Int]) = getIf(in, _%2==0)
@StrumentiResistenti
StrumentiResistenti / check_sqlite3_seq.c
Last active August 5, 2016 18:26
libDBI sqlite3 sequence number test
/*
* Compile as:
*
* gcc -o check_sqlite3_seq check_sqlite3_seq.c -ldbi
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>