Skip to content

Instantly share code, notes, and snippets.

View Gyvastis's full-sized avatar

Vaidas Bagdonas Gyvastis

View GitHub Profile
@Gyvastis
Gyvastis / calculateSentanceScore.php
Last active November 9, 2018 09:00
Calculate string/sentance score for score-based sorting. Use case: elasticsearch score-based search.
<?php
$alphabeth = strtolower('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$sentances = [
'Fifa 2018',
'Grand Theft Auto V',
'Sims 5',
'Hitman',
'Assasins Creed',
@Gyvastis
Gyvastis / generateInitialMigration.php
Created March 24, 2020 07:10
Generate initial Doctrine Migration from SQL dump
<?php
$sqlDump = file_get_contents(dirname(__FILE__) . '/dump.sql');
$sqlStatements = explode(";\n", $sqlDump);
$sqlStatements = array_filter($sqlStatements, function($statement) {
$statement = trim($statement);
return strpos($statement, '#') !== 0 && strpos($statement, '/*') !== 0;
});
$sqlStatements = array_map(function($statement){
@Gyvastis
Gyvastis / dbref_database_rename.js
Created September 21, 2020 13:21
Rename MongoDB DBRef database name in all collections.
var newDbName = 'comsave-miner';
db.getCollectionNames().forEach(function (collName) {
var collDocsUpdated = 0;
db[collName].find().forEach(function (r) {
var refUpdated = false;
Object.keys(r).forEach(function(rKey){
if(!r[rKey]) {
return;
@Gyvastis
Gyvastis / postal-codes.json
Created October 7, 2020 08:37 — forked from jamesbar2/postal-codes.json
Global postal codes regex formats
[{
"Note": "The first two digits (ranging from 10–43) correspond to the province, while the last two digits correspond either to the city/delivery zone (range 01–50) or to the district/delivery zone (range 51–99). Afghanistan Postal code lookup",
"Country": "Afghanistan",
"ISO": "AF",
"Format": "NNNN",
"Regex": "^\\d{4}$"
}, {
"Note": "With Finland, first two numbers are 22.",
"Country": "Åland Islands",
"ISO": "AX",
@Gyvastis
Gyvastis / zipcode.go
Last active October 14, 2020 10:01
Global ZipCode regexes
package helpers
import (
"errors"
"fmt"
"regexp"
)
type ZipCode struct{}
@Gyvastis
Gyvastis / gist:4ba63fa9b0d80973c677a48d7b52e4ee
Created October 14, 2020 10:15
JSON country codes and country names list
{
"AF": "Afghanistan",
"AX": "Åland Islands",
"AL": "Albania",
"DZ": "Algeria",
"AS": "American Samoa",
"AD": "Andorra",
"AO": "Angola",
"AI": "Anguilla",
"AQ": "Antarctica",
@Gyvastis
Gyvastis / test.go
Created October 22, 2020 11:09
golang testify return on consecutive calls
func() {
consecutive := -1
responseMocks := []string{
responseString1,
responseString2,
}
httpClientMock.On("SendRequest", req).Return(func() *http.Response {
consecutive++
return &http.Response{
StatusCode: 200,
@Gyvastis
Gyvastis / translate.js
Created October 28, 2020 08:53
Bing translate
const translate = text => fetch("https://www.bing.com/ttranslatev3", {
"headers": {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
"content-type": "application/x-www-form-urlencoded",
},
"body": `&fromLang=nb&text=${encodeURIComponent(text)}&to=en`,
"method": "POST",
"mode": "cors"
})
.then(response => response.json())
@Gyvastis
Gyvastis / gist:036398f6d773c1d68563f9f2cc95cede
Created November 19, 2020 14:59
php currency enumerable
<?php
final class CurrencyEnum extends BaseEnumerable
{
public const ALL = 'ALL';
public const AFN = 'AFN';
public const ARS = 'ARS';
public const AWG = 'AWG';
public const AUD = 'AUD';
public const AZN = 'AZN';
@Gyvastis
Gyvastis / visa_free_days_left.php
Last active March 4, 2021 19:42
visa 90 days in 180 days calculator
<?php
$visitDates = [
['2020-06-16', '2020-06-30'],
['2020-07-23', '2020-07-28'],
['2020-10-09', '2020-11-04'],
['2020-12-15', '2021-01-16'],
['2021-01-30', '2021-02-26'],
];