Skip to content

Instantly share code, notes, and snippets.

<?php
function peselValidate(string $str)
{
if (!preg_match('/^[0-9]{11}$/', $str)) {
return false;
}
$arrSteps = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
$intSum = 0;
@mikemix
mikemix / app.js
Created May 6, 2016 06:48
Improve angular performance
myApp.config(['$compileProvider', function ($compileProvider) {
$compileProvider.debugInfoEnabled(false);
}]);
<?php
$this->eventStore->beginTransaction();
foreach ($data as $domain => $records) {
$aggregate = Domain::create(Uuid::uuid4(), new DomainId($domain));
foreach ($records as $record) {
try {
$aggregate->addRecord(...);
@mikemix
mikemix / encrypted_string.php
Created February 10, 2017 06:46
Encrypted on-fly Doctrine string type
<?php
namespace AppBundle\DBAL\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
final class EncryptedStringType extends Type
{
const ENCRYPTED_STRING = 'encrypted_string';
@mikemix
mikemix / form.php
Created February 14, 2017 09:29
Dynamic validation groups
<?php
// form skipped for brevity
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'validation_groups' => function (FormInterface $form) {
return $form->getConfig()->getOption('option_name') ?
['group1', 'group2'],
['group3'];
@mikemix
mikemix / floating-banner.html
Created December 15, 2017 09:06
Sliding banner on the bottom of the page for Revive Ad Server
<!-- required html -->
<a href="{clickurl}http://redirect.url" id="p_234231210934">
<img src="http://via.placeholder.com/1500x35">
</a>
<style>#p_234231210934{display:block;height:35px;width:100%;overflow:hidden;position:relative}#p_234231210934 img{display:inline;position:absolute;top:0}</style>
<!-- followed by the script (not minified) -->
<script>
var pasek=document.getElementById('p_234231210934');
var initImage=pasek.getElementsByTagName('img')[0];
@mikemix
mikemix / compile.sh
Last active April 20, 2018 08:53
Raspberry PI/ZERO DHT11 sensor reader
#!/bin/bash -e
gcc dht11_read.c -lwiringPi -o dht11_read
const int sensorPin = 3;
const int max_ppm = 2000;
long ppm=0;
unsigned long duration;
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
}
@mikemix
mikemix / qmail-break-detection.sh
Last active May 24, 2018 09:10
Qmail possible break detection - automatic account lock cron script
#!/bin/bash -e
###########################################################
# Qmail authentication log analyzer
# Detects too many different IP connections in single day
#
# If anomaly is detected, user account is locked
# action is logged and administrator is notified by SMS
###########################################################
##
@mikemix
mikemix / debug-console
Last active July 13, 2018 07:59
Shell script wrapper for debugging Symfony console applications with XDebug and Docker
#!/bin/sh -e
##
# Fill this accordingly!
# The "server" has to be configured in phpStorm (Settings > Language & Frameworks > PHP > Servers).
# Put the name inside the quotes
phpstorm_server_name="localhost"
##
# Put me in bin/ alongside the console script