Skip to content

Instantly share code, notes, and snippets.

@dg
dg / html.regex
Last active January 10, 2024 08:30
Regular expression for parsing HTML
~
(?(DEFINE)
(?<entity>
&
(
[a-z][a-z0-9]+ # named entity
|
\#\d+ # decimal number
|
I have just discovered a great feature of composer:
composer update --lock
It saves a lot of time when you merge branches with composer.lock file changes in both branches.
Just resolve conflict by applying --ours version of the file (or --theirs, it really doesn't matter) and then run
`composer update --lock `.
Composer will do all the dirty work for you and update composer.lock file according to composer.json changes
and install new packages. The rest of packages in composer are not changed.
@mkaraki
mkaraki / install_ffmpeg_codec_for_opera.sh
Created February 15, 2020 10:09
Install ffmpeg codec for Opera in Linux (Ubuntu)
#!/bin/bash
# for Ubuntu
# Install pre-requirements
sudo apt-get update
sudo apt-get install -y chromium-codecs-ffmpeg-extra
# Import to opera
sudo ln -sf /usr/lib/chromium-browser/libffmpeg.so /usr/lib/x86_64-linux-gnu/opera/libffmpeg.so
@dg
dg / composing.presenters.php
Created May 31, 2018 14:00
Composing presenters without inheritance
<?php
// composing presenters without inheritance
// (requires nette/application 2.4.11)
trait RequireLoggedUser
{
public function injectRequireLoggedUser()
{
@JanTvrdik
JanTvrdik / uuid.php
Last active February 14, 2018 14:11
PHP Fast and simple UUID v4 generator
<?php
function generateUuidWithoutDashes(): string
{
$uuidBin = random_bytes(16);
$uuidBin &= "\xFF\xFF\xFF\xFF\xFF\xFF\x0F\xFF\x3F\xFF\xFF\xFF\xFF\xFF\xFF\xFF";
$uuidBin |= "\x00\x00\x00\x00\x00\x00\x40\x00\x80\x00\x00\x00\x00\x00\x00\x00";
$uuidHex = bin2hex($uuidBin);
return $uuidHex;
@hauke96
hauke96 / libffmpeg_vivaldi.md
Last active July 4, 2023 18:56
Install libffmpeg.so in vivaldi

Install libffmpeg.so in vivaldi

This short instruction shows how to install libffmpeg.so in vivaldi to play e.g. mp4 videos.

I use the ubuntu repository for that but this is just one way to get the file.

1. Download .deb package

Go to http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/ and choose the latest chromium-codecs-ffmpeg-extra and download it.

For example: chromium-codecs-ffmpeg-extra_58.0.3029.110-0ubuntu1.1354_amd64.deb

@geekmanager
geekmanager / make-git-use-sublime.markdown
Last active July 3, 2023 12:22
Making git use Sublime Text for rebase etc

Making git use Sublime Text

First up, let's make Sublime Text 2 available from the command line in terminal, by creating a link to subl which is the launcher from terminal:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

(added bonus of this approach is when you upgrade to ST3 or change text editor, you can just redirect the symlink).

If there's any chance that bash doesn't check usr/local/bin then use [Launch Sublime Text 2 from Mac OSX Terminal] for more detailed instructions on how to make this happen.

@milo
milo / github-webhook-handler.php
Last active July 26, 2023 15:29
GitHub Webhook Handler
<?php
/**
* GitHub webhook handler template.
*
* @see https://docs.github.com/webhooks/
* @author Miloslav Hůla (https://github.com/milo)
*/
$hookSecret = 's.e.c.r.e.t'; # set NULL to disable check
@mibk
mibk / BaseQuery.php
Last active December 14, 2018 10:36
LeanMapperQuery suggested base classes.
<?php
namespace Model\Entity;
use LeanMapperQuery\Entity;
use LeanMapperQuery\IQuery;
use Model\Query\EntityQuery;
class BaseEntity extends Entity
{
@dg
dg / websocket.html
Created August 11, 2013 15:54
WebSocket communication between PHP and single client
<!doctype html>
<script>
if ("WebSocket" in window) {
var ws = new WebSocket("ws://127.0.0.1:31339");
ws.onopen = function() {
console.log('connected');
};
ws.onerror = function(e) {