Skip to content

Instantly share code, notes, and snippets.

@juzna
juzna / 01-server-config-in-git.md
Last active November 9, 2021 07:27
Server Configuration in git

Server Configuration in git

With git you can have anything versioned. You're used to version your code, which is a bunch of files. Your server configuration (on Linux) is also just a bunch of files, so it can be versioned as well.

The idea is simple: create a git repository in /etc/ and commit everytime you change any configuration of your server. Written in code:

cd /etc
git init
git add .
@Dare-NZ
Dare-NZ / getAvgLuminance.php
Last active February 13, 2023 07:35
A php function that gets the average brightness of an image
<?php
function getAvgLuminance($filename, $num_samples=30) {
// needs a mimetype check
$img = imagecreatefromjpeg($filename);
$width = imagesx($img);
$height = imagesy($img);
$x_step = intval($width/$num_samples);
$y_step = intval($height/$num_samples);
@lexaurin
lexaurin / .gitconfig
Last active December 11, 2015 11:28
How to manage changelog by git tags? Prefix tags with "v" letter and use this alias:
[alias]
changelog = "!git tag -l v* -n20 | sed -n 'H;${;g;s/\\n[^v]/\\x00/g;p}' | sort -rV | tr \\\\000 \\\\n | less"
@juzna
juzna / intro.md
Created August 20, 2012 19:19
Nette\Object performance tests

Nette\Object performance tests

I guess you already saw a short note Latency Numbers Every Programmer Should Know. I wanted to check how well Nette performs with its magic properties on Nette\Object.

You can see the testing code below together with raw output on my machine.

It show how much time in seconds it took to execute one million iterations of a particular action, thus it is also time in microseconds of one such call. You should compare it to null test, which execute empty iterations.

Results

@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of