Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* PHP Anonymous Object
*/
class AnObj
{
protected $methods = array();
public function __construct(array $options)
@hlev
hlev / mac_regex.php
Last active May 28, 2019 23:10
PHP regexp testing for valid MAC address
<?php
/**
* To match aa:bb:cc:dd:ee:ff, aabbcddeeff, aa-bb-cc-dd-ee-ff formats in case-insensitive manner
*/
$macAddress = '2a:3b:2c:1d:44:23';
// 1
echo preg_match('/^(?:(?:[0-9a-f]{2}[\:]{1}){5}|(?:[0-9a-f]{2}[-]{1}){5}|(?:[0-9a-f]{2}){5})[0-9a-f]{2}$/i', $macAddress);
@hlev
hlev / DataUri.php
Last active November 30, 2015 20:24
A convenient class for working with Data URIs in PHP
<?php
/* The MIT License (MIT)
* Copyright (c) 2015 FlyingTopHat ([email protected])
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
@hlev
hlev / gist:cd27324aa53c4143d565a1cac50bbf3a
Created October 12, 2016 15:30 — forked from SzymonPobiega/gist:5220595
DDD/CQRS/ES/Architecture videos

If you have two days to learn the very basics of modelling, Domain-Driven Design, CQRS and Event Sourcing, here's what you should do:

In the evenings read the [Domain-Driven Design Quickly Minibook]{http://www.infoq.com/minibooks/domain-driven-design-quickly}. During the day watch following great videos (in this order):

  1. Eric Evans' [What I've learned about DDD since the book]{http://www.infoq.com/presentations/ddd-eric-evans}
  2. Eric Evans' [Strategic Design - Responsibility Traps]{http://www.infoq.com/presentations/design-strategic-eric-evans}
  3. Udi Dahan's [Avoid a Failed SOA: Business & Autonomous Components to the Rescue]{http://www.infoq.com/presentations/SOA-Business-Autonomous-Components}
  4. Udi Dahan's [Command-Query Responsibility Segregation]{http://www.infoq.com/presentations/Command-Query-Responsibility-Segregation}
  5. Greg Young's [Unshackle Your Domain]{http://www.infoq.com/presentations/greg-young-unshackle-qcon08}
  6. Eric Evans' [Acknowledging CAP at the Root -- in the Domain Model]{ht
@hlev
hlev / mapgen.md
Last active October 7, 2017 12:29
XCSoar mapgen usage example

As of 2017-10-06: If the XCSoar Map Generator site does not work or you want to use the Map Generator in your own project, you can do so as described here. You don't need to know any programming language if you only want to generate maps for XCSoar.

Windows

Disclaimer: I'm writing this up based on my assumptions, have not tried Windows, so YMMV. (!) Read the comment first!

All the required tools and dependencies are available on Windows

@hlev
hlev / h264_1080p_to_720p_ffmpeg.md
Last active May 31, 2021 04:26
Transcoding and scaling native h264 portrait video with ffmpeg

Original

https://vimeo.com/166500954

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vertical.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41isomavc1
    creation_time   : 2016-05-20 00:41:40
@hlev
hlev / scan2pdf
Created November 24, 2017 12:29
Helper script to scan straight to PDF with network scanner on the LAN using scanimage and unoconv
#!/usr/bin/env bash
# usage: scan2pdf output
# results in: output.pdf
# possible improvements:
# - config file for IP, default resolution, sleep time
# - device discovery
# - platform-agnostic temp file usage
# - investigate parsing errors of otherwise successful conversions
tmpfile=$(mktemp /tmp/scan.XXXX);
@hlev
hlev / 5perc.md
Last active January 29, 2018 07:33
3.3
@hlev
hlev / i3confsnip
Last active December 10, 2018 11:53
i3 config snippets
# Custom app launcher
set $ides "IDEs [p]hpstorm [c]lion [i]ntellij"
bindsym $mod+i mode $ides
mode $ides {
bindsym p exec --no-startup-id "i3-msg 'workspace 2; exec /opt/jetbrains/phpstorm_latest/bin/phpstorm.sh; mode \\"default\\"'"
bindsym c exec --no-startup-id "i3-msg 'workspace 2; exec /opt/jetbrains/clion_latest/bin/clion.sh; mode \\"default\\"'"
bindsym i exec --no-startup-id "i3-msg 'workspace 2; exec /opt/jetbrains/intellij_latest/bin/idea.sh; mode \\"default\\"'"
bindsym Return mode "default"
bindsym Escape mode "default"
@hlev
hlev / .diff
Last active November 5, 2018 10:59
wpebackend-rdk
# $ git diff stable master package/wpe/wpebackend-rdk/wpebackend-rdk.mk
# The stable branch still uses WPELauncher, the master branch uses WPEFramework
# They build wpebackend-rdk differently
diff --git a/package/wpe/wpebackend-rdk/wpebackend-rdk.mk b/package/wpe/wpebackend-rdk/wpebackend-rdk.mk
index 5469664227..95821db3fd 100644
--- a/package/wpe/wpebackend-rdk/wpebackend-rdk.mk
+++ b/package/wpe/wpebackend-rdk/wpebackend-rdk.mk
@@ -4,7 +4,7 @@
#