Skip to content

Instantly share code, notes, and snippets.

View mtarnovan's full-sized avatar

Mihai Târnovan mtarnovan

View GitHub Profile
@mtarnovan
mtarnovan / day1.exs
Created December 1, 2018 19:33
adventofcode-day1
defmodule Day1 do
def read_input do
"input.txt"
|> File.stream!()
|> Stream.map(&String.trim/1)
|> Stream.map(&String.to_integer/1)
end
def combine_freq(input) do
Enum.reduce(input, &Kernel.+/2)
@mtarnovan
mtarnovan / daterange_covered.sql
Created October 17, 2018 13:15
Postgres (date) range coverage function
CREATE IF NOT EXISTS EXTENSION btree_gist;
CREATE TABLE split_vat (
cif varchar,
interval daterange NOT NULL,
applies_split_vat boolean NOT NULL,
EXCLUDE USING
gist (interval WITH &&, cif WITH =)
);
@mtarnovan
mtarnovan / company.php
Last active July 3, 2018 11:03
openapi php company code sample
<?php
$ch = curl_init();
$api_key = getenv('OPENAPI_KEY');
$sample_cif = '13548146';
curl_setopt($ch, CURLOPT_URL, "https://api.openapi.ro/api/companies/$sample_cif");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
@mtarnovan
mtarnovan / openapi_test.js
Last active April 5, 2018 11:31
openapi.ro test request from browser js console
const apiKey = prompt('Introdu cheia ta API. Aceasta o gasesti in contul tau openapi')
var testCIF = prompt('Introdu un CIF valid sau lasa gol pentru un CIF de test') || '13548146'
const xhr = new XMLHttpRequest()
xhr.open('GET', `https://api.openapi.ro/v1/companies/${testCIF}`, true)
xhr.setRequestHeader('x-api-key', apiKey)
xhr.send()
const processResponse = (e) => {
if (xhr.readyState == 4) {
\set QUIET 1
\pset null '¤'
\set PROMPT1 '%[%033[1m%][%/] # '
-- SELECT * FROM<enter>. %R shows what type of input it expects.
\set PROMPT2 '... > '
\timing
\x auto
mtarnovan@vps1 ~ # curl --progress-bar -L --fail --retry 3 --retry-delay 1 --connect-timeout 5 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/cedar-14/ruby-2.3.0.tgz -O
######################################################################## 100.0%
mtarnovan@vps1 ~ # md5sum ruby-2.3.0.tgz
dd963e5a41247a7d4e8817efe95e8123 ruby-2.3.0.tgz
mtarnovan@vps2:~$ curl --progress-bar -L --fail --retry 3 --retry-delay 1 --connect-timeout 5 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/cedar-14/ruby-2.3.0.tgz -O
######################### 35.0%Warning: Transient problem: timeout Will retry in 1 seconds. 3 retries left.
Throwing away 6370974 bytes
###################### 31.3%Warning: Transient problem: timeout Will retry in 1 seconds. 2 retries left.
Throwing away 5692062 bytes
@mtarnovan
mtarnovan / foo.md
Last active August 31, 2016 15:31

BILANȚ DE la data de 3 Entitatea: PICANT ABATOR SI PRELUCRAREA CARN Județ 29: Prahova, Localitate: Albești Paleologu, Str. - n Număr din registrul comerțului: J29/1447/1997 Cod unic de înregistrare: 9993706 Forma de proprietate: 34 - Societăți comerciale pe acțiu Activitatea preponderentă (cod și denumire clasa CAEN PRELUCRAREA CARNII - S.A. LICHIDARE

Keybase proof

I hereby claim:

  • I am mtarnovan on github.
  • I am mtarnovan (https://keybase.io/mtarnovan) on keybase.
  • I have a public key whose fingerprint is 28D4 3A99 DD98 7344 211C 4682 5246 B8DE 571A 1E21

To claim this, I am signing this object:

defmodule CifValidator do
@test_key "753217532"
def valid_cif?(cif) do
well_formed?(cif) && control_sum_matches?(cif)
end
defp control_sum_matches?(cif) do
test_key = @test_key
|> to_integer_list
# a mapping from turkish to romanian code points
# Ş => Ș etc
TURKISH_TO_ROMANIAN = {
350 => 536,
351 => 537,
354 => 538,
355 => 539
}.freeze
def turkish_to_romanian(string)