Skip to content

Instantly share code, notes, and snippets.

View Gyvastis's full-sized avatar

Vaidas Bagdonas Gyvastis

View GitHub Profile
@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 / 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 / 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 / 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',