Skip to content

Instantly share code, notes, and snippets.

View Addvilz's full-sized avatar

Matīss Addvilz

View GitHub Profile
@Addvilz
Addvilz / gist:3024731
Created June 30, 2012 17:28
MySQLi extends
<?php
/**
* SQL base class, extends MySQLi
*
*/
class Sql extends MySQLi{
/**
* MySQLi __construct override with autoconnect
*
* @return void
@Addvilz
Addvilz / gist:3025873
Created June 30, 2012 22:38
Excelent way to calculate durations of multiple intervals grouped by id
SELECT SUM(TIME_TO_SEC(TIMEDIFF(`to`,`from`))) as `spent` FROM `intervals` GROUP BY `id`;
@Addvilz
Addvilz / gist:3426914
Created August 22, 2012 15:44
Get hdd info
exec('/sbin/udevadm info --query=property --name=sda',$arr,$out);
$dopts = array();
foreach($arr as $item){
$parts = explode('=',$item);
$dopts[$parts[0]] = $parts[1];
}
print_r($dopts);
@Addvilz
Addvilz / hgpack.sh
Last active October 13, 2015 05:38
Packs files changed between hg revs
#!/bin/bash
if [ -z "$1" ]; then
echo "No start revision"
exit 1;
fi
if [ -z "$2" ]; then
echo "No end revision"
exit 1;
fi
@Addvilz
Addvilz / gist:3e566f5a1a5cb769b4ad
Last active August 30, 2016 12:47
php-cs-precommit
#!/usr/bin/php
<?php
function progress($i, $total, $label = null, $end=null){
$percent = ceil(($i / $total) * 100);
$barSize = ceil($percent/2);
$blankSize = 50 - $barSize;
if(($blankSize + $barSize) < 50){
$blankSize += (50 - ($blankSize + $barSize));
}
@Addvilz
Addvilz / mysqlsnap-backup.sh
Last active August 29, 2015 14:15
Snapshot mySql database to another local database
#!/bin/bash
echo "Source database name:"
read sourceDb
if [ -z "${sourceDb-unset}" ]
then
echo "Your mission, should you choose to accept it is to enter a source database name..."
exit 1
fi
@Addvilz
Addvilz / gist:5f7604224ce0238af7fd
Created March 6, 2015 14:08
phpstorm setter with self reference and correct type hints
## Editor>File and Code Templates>Code>PHP Setter Method
#set($typeHintText = "$TYPE_HINT ")
## First we check against a blacklist of primitive and other common types used in documentation.
#set($nonTypeHintableTypes = ["", "string", "int", "mixed", "number", "void", "object", "real", "double", "float", "resource", "null", "bool", "boolean"])
#foreach($nonTypeHintableType in $nonTypeHintableTypes)
#if ($nonTypeHintableType == $TYPE_HINT)
#set($typeHintText = "")
#end
#end
## Make sure the type hint actually looks like a legal php class name(permitting namespaces too) for future proofing reasons.
<?php
/**
* I would rather solve this problem by having a Entity, a dumb business model that contains
* all the data, is dumb (yep), has no logic and represents a data type.
*
* Populate it once and reuse the type where applicable, as it will give many advantages against
* having to juggle around bazillion of separate variables.
*
* a) your business logic and data will be clearly separated - SOC;
* b) KISS DRY;
namespace Hello.World
import Iterator
import List
import LinkedList as BaseList
import Map
import OtherInterface
Main
const EXCL_MARK is '!'
@Addvilz
Addvilz / gist:aebef1637cf8d3da8b70
Created July 22, 2015 11:15
Exploiting auth system without feedback to determine username presence
var inputUsername
var inputPassword
user = retrieve from storage with matching inputUsername
if user not exists
return 'No matching user'
if user.password not match hash(inputPassword)
return 'No matching user'