Skip to content

Instantly share code, notes, and snippets.

@lajosbencz
lajosbencz / ConsoleParameters.php
Last active May 3, 2019
Command line parameters helper class
View ConsoleParameters.php
<?php
use ArrayAccess;
class ConsoleParameters implements ArrayAccess
{
/**
* Prefix for flag names
* @var string
*/
@lajosbencz
lajosbencz / ConvertByteSize.php
Created Sep 17, 2015
Convert between byte size units
View ConvertByteSize.php
<?php
namespace LajosBencz;
class ConvertByteSize
{
const FORMAT_BYTE_SIZE_PATTERN = '(yotta|zetta|exa|peta|tera|giga|mega|kilo|y|z|e|p|t|g|m|k)\s*(bit|byte|b)?';
public static $formatByteSize_Unit = 'mB';
public static $formatByteSize_Format = '%0.2f %s';
View TaskInterface.php
<?php
interface TaskInterface
{
/**
* Assign the first number
* @param int $value
* @return $this
*/
public function setA($value);
View js-delegates.html
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<script>
$(function(){
$('#add_default').click(function(){
$('#list').append($('<li><a>Default</a></li>'));
});
$('#add_clickable').click(function(){
$('#list').append($('<li><a class="clickme">Clickable</a></li>'));
@lajosbencz
lajosbencz / ProgressBar.php
Created May 1, 2016
Multi-line progress bar for terminal
View ProgressBar.php
<?php
class ProgressBar
{
const NL = PHP_EOL;
/** Pattern used to match placeholders in message formats */
const PATTERN_FORMAT = "/%(?'name'[^\\s%:]+)(:(?'format'[^%]+))?%/";
/** Default format for progress update message */
@lajosbencz
lajosbencz / amdgpu-pro-wizard.sh
Created Sep 19, 2017
Downloads and installs latest AMDGPU-PRO drivers from the official AMD website
View amdgpu-pro-wizard.sh
#!/bin/bash
# amdgpu-pro-wizard.sh
# Downloads and installs latest AMDGPU-PRO drivers from the official AMD website
URL="http://support.amd.com/en-us/kb-articles/Pages/AMDGPU-PRO-Driver-for-Linux-Release-Notes.aspx"
DIR="/tmp/.amdgpu-pro-install-9811a15y85p71m/"
HTML="list.html"
PAT="www2.ati.com/drivers/linux"
REF="http://support.amd.com"
View PhalconRedisAdapter.php
use Phalcon\Session\AdapterInterface;
use Phalcon\Cache\Backend\Redis as RedisCache;
use Phalcon\Cache\Frontend\None as FrontendNone;
class Redis implements \SessionHandlerInterface, AdapterInterface
{
const SESSION_ACTIVE = 2;
const SESSION_NONE = 1;
@lajosbencz
lajosbencz / gitpub.php
Last active Nov 7, 2018
Script for bumping semantic versioned packages to git remote
View gitpub.php
<?php
/**
* Script for bumping semantic versioned packages to git remote
*
* @version 0.1.0
* @author Lajos Bencz <lazos@lazos.me>
* @license MIT
*/
if (!is_dir('.git')) {
@lajosbencz
lajosbencz / create-swap.sh
Created Dec 18, 2021
Ubuntu 20 create swap space on disk
View create-swap.sh
#!/bin/bash
SIZE="$1"
FILE="/var/swap.img"
SWPS=10
CHPR=50
if [ -z "$SIZE" ]; then
echo "first argument must be size (fallocate -l)"
exit
@lajosbencz
lajosbencz / disable-snapd.sh
Last active Dec 18, 2021
Ubuntu 20 disable snapd
View disable-snapd.sh
#!/bin/bash
systemctl stop snapd && systemctl disable snapd && systemctl mask snapd && \
apt purge snapd -y && \
rm -fr ~/snap /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd