Skip to content

Instantly share code, notes, and snippets.

View mlask's full-sized avatar
😶
No comments.

Marcin Laber mlask

😶
No comments.
View GitHub Profile
@mlask
mlask / pesel.php
Created September 23, 2014 13:00
Weryfikacja numeru PESEL
<?php
function check_pesel_number ($number)
{
$w = array(1, 3, 7, 9, 1, 3, 7, 9, 1, 3);
if (($l = strlen($number = preg_replace('/[^0-9]/', '', $number))) !== count($w) + 1) return false;
for ($s = $i = 0; $i < $l - 1; $i ++)
$s += $number[$i] * $w[$i];
return $number[$l - 1] == ((10 - ($s % 10)) % 10);
}
@mlask
mlask / nip.php
Created September 23, 2014 13:03
Weryfikacja numeru NIP
<?php
function check_nip_number ($number)
{
$w = array(6, 5, 7, 2, 3, 4, 5, 6, 7);
if (($l = strlen($number = preg_replace('/[^0-9]/', '', $number))) !== count($w) + 1) return false;
for ($s = $i = 0; $i < $l - 1; $i ++)
$s += $number[$i] * $w[$i];
return (10 > ($c = ($s % 11))) && $number[$l - 1] == $c;
}
@mlask
mlask / regon.php
Created September 23, 2014 13:03
Weryfikacja numeru REGON
<?php
function check_regon_number ($number)
{
$w = array(7 => array(2, 3, 4, 5, 6, 7), 9 => array(8, 9, 2, 3, 4, 5, 6, 7), 14 => array(2, 4, 8, 5, 0, 9, 7, 3, 6, 1, 2, 4, 8));
if (!isset($w[$l = strlen($number = preg_replace('/[^0-9]/', '', $number))])) return false;
for ($s = $i = 0; $i < $l - 1; $i ++)
$s += $number[$i] * $w[$l][$i];
return $number[$l - 1] == (($s % 11) % 10);
}
@mlask
mlask / dowod_osobisty.php
Created September 23, 2014 13:04
Weryfikacja numeru Dowodu Osobistego
<?php
function check_do_number ($number)
{
$t = 0;
$n = array();
$w = array(7, 3, 1);
if (!preg_match('/^([A-Z]+)(\d{1})(\d+)$/', strtoupper($number), $n)) return false;
foreach (str_split($n[1] . $n[3]) as $i => $l)
$t += $w[$i % 3] * (is_numeric($l) ? $l : (ord($l) - 55));
return ($t % 10) == (int)$n[2] ? true : false;
@mlask
mlask / pwz.php
Created September 23, 2014 13:05
Weryfikacja numeru PWZ
<?php
function check_pwz_number ($number)
{
if (strlen($number) != 7 || preg_match('/^0+$/', $number)) return false;
$c = (int)$number[0];
$n = substr($number, 1);
$s = 0;
for ($i = 1; $i <= 6; $i ++) $s += (int)$n[$i - 1] * $i;
return ($s % 11) == $c ? true : false;
}
@mlask
mlask / svn-changes
Created June 27, 2016 22:03
Export changed (and, optionally, uncommited) files from SVN repository
#!/usr/bin/php
<?php
/**
* Options:
* -r rev_from:rev_to -- revision range to export
* -u username -- svn username (optional)
* -p password -- svn password (optional)
* -n -- export with uncommited files (optional)
*/
$opts = getopt('r:u:p:n');
@mlask
mlask / svn-sync
Last active May 23, 2017 13:23
SVN repository quick sync script
#!/usr/bin/php
<?php
$status = shell_exec('svn status --non-interactive');
if (strlen(trim($status)) > 0)
{
$status = explode("\n", trim($status));
echo("Syncing repository...\n");
foreach ($status as $item)
{
if (preg_match('/^\?\s+(.*)(?<!CVS\/Entries\.Log)$/', $item, $match))
@mlask
mlask / update_curl.sh
Last active May 25, 2017 09:05 — forked from fideloper/update_curl.sh
Update curl on Ubuntu 14.04
#! /usr/bin/env bash
# Install any build dependencies needed for curl
sudo apt-get build-dep curl
# Get latest (as of Feb 25, 2016) libcurl
mkdri
cd ~/curl
wget https://curl.haxx.se/download/curl-7.54.0.tar.bz2
tar -xvjf curl-7.54.0.tar.bz2
@mlask
mlask / testcolors.sh
Last active October 7, 2020 13:13
ANSI color codes
#!/bin/zsh
for a in {30..47}; do (for b in {0..9}; do echo -n "\x1b[$b;$a""m" " $b;$a \x1b[0m";done;); echo "\x1b[0m"; done
for a in {90..107}; do (for b in {0..9}; do echo -n "\x1b[$b;$a""m" " $b;$a \x1b[0m";done;); echo "\x1b[0m"; done
<?php
new class
{
public function __construct ()
{
$args = explode("\n", trim(file_get_contents('php://stdin')));
$carg = count($args);
$this->log('===== Action started === %d path(s) to process =====', $carg);