Skip to content

Instantly share code, notes, and snippets.

View fordnox's full-sized avatar
🍕
Eating pizza

Andrius Putna fordnox

🍕
Eating pizza
View GitHub Profile
@fordnox
fordnox / execute.php
Last active September 16, 2020 07:48
Execute shell command with timeout and converting stderr to Exception if any
<?php
/**
* @param int $timeout - max process execution time in seconds until it is terminated
**/
function execute($cmd, $stdin = null, $timeout = 600)
{
$this->log->debug("executing: " . $cmd . " ". $stdin);
$cmd = str_replace("\n", "", $cmd);
$cmd = str_replace("\r", "", $cmd);
@fordnox
fordnox / check-ftp.php
Created April 5, 2017 13:17
Check ftp connection with PHP
<?php
$host = 'example.com';
$password = 'pass';
$username = 'username';
try {
$result = checkFtp($host, $username, $password);
} catch(Exception $e) {
$result = $e->getMessage();
}
@fordnox
fordnox / domain.conf
Created December 13, 2014 08:20
Split clients nginx conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
@fordnox
fordnox / converter.sh
Created December 21, 2019 16:29
Convert image formats on MacOS
#!/bin/bash
#Convert all jpeg files in current dir to PNG in new folder Converted
sips -s format png *.jpeg –out Converted
#Convert all tiff files in current dir to jpeg in new folder Converted
sips -s format jpeg *.tiff –out Converted
<?php
echo date('c');
?>
@fordnox
fordnox / index.php
Last active May 14, 2019 11:41
this is an example of index pafge
<!DOCTYPE html>
<html>
<body>
<?php
echo "This is a very simple php example.";
?>
</body>
</html>
@fordnox
fordnox / index.html
Created April 2, 2019 13:36
this is an example of index pafge
<!DOCTYPE html>
<html>
<body>
<?php
echo "This is a very simple php example.";
?>
</body>
</html>
@fordnox
fordnox / crop.sh
Created January 24, 2019 20:12
crop resize sharpen with image magic
convert *.png -set filename:base "%[basename]" -crop 2048x2048+0+0 -resize 640x640 -sharpen 0x1 res/"%[filename:base].png"
@fordnox
fordnox / flac2mp3.sh
Created August 26, 2018 19:47
flac to mp3 converter
#!/bin/bash
for f in "$@"; do
echo "$f"
[[ "$f" != *.flac ]] && continue
album="$(metaflac --show-tag=album "$f" | sed 's/[^=]*=//')"
artist="$(metaflac --show-tag=artist "$f" | sed 's/[^=]*=//')"
date="$(metaflac --show-tag=date "$f" | sed 's/[^=]*=//')"
title="$(metaflac --show-tag=title "$f" | sed 's/[^=]*=//')"
year="$(metaflac --show-tag=date "$f" | sed 's/[^=]*=//')"
@fordnox
fordnox / date_range.php
Created November 13, 2014 11:08
Date ranges in PHP
<?php
private function _getDataRange($range)
{
$lowerdate = null;
$upperdate = null;
switch ($range) {
case 'today':
$lowerdate = date('Y-m-d 00:00:00');