Skip to content

Instantly share code, notes, and snippets.

View Addvilz's full-sized avatar

Matīss Addvilz

View GitHub Profile
@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: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 / 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: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: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'
namespace Hello.World
import Iterator
import List
import LinkedList as BaseList
import Map
import OtherInterface
Main
const EXCL_MARK is '!'
<?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;
@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