Skip to content

Instantly share code, notes, and snippets.

View nielsmh's full-sized avatar

Niels Martin Hansen nielsmh

View GitHub Profile
@nielsmh
nielsmh / gist:5444959
Created April 23, 2013 16:08
Crazy PHP. Consistency, don't need that. You can apply the "new" operator to a variable containing a string, but you can't apply it to a string literal. Why are those two different at all?
$ php -a
Interactive shell
php > class Lol { }
php > $a = new Lol;
php > var_dump($a);
object(Lol)#1 (0) {
}
php > $b = new 'Lol';
PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in php shell code on line 1
def prettyfy(o, level=''):
nextlevel = level + ' '
if isinstance(o, dict):
return '{\n' + ',\n'.join(['{}{!s}: {}'.format(nextlevel, k, prettyfy(v, nextlevel)) for k, v in o.iteritems()]) + '\n' + level + '}'
elif isinstance(o, list):
return '[\n' + ',\n'.join(['{}{}'.format(nextlevel, prettyfy(v, nextlevel)) for v in iter(o)]) + '\n' + level + ']'
elif isinstance(o, set):
return '{\n' + ',\n'.join(['{}{}'.format(nextlevel, prettyfy(v, nextlevel)) for v in iter(o)]) + '\n' + level + '}'
elif isinstance(o, tuple):
return '(\n' + ',\n'.join(['{}{}'.format(nextlevel, prettyfy(v, nextlevel)) for v in iter(o)]) + '\n' + level + ')'
@nielsmh
nielsmh / extradata.lua
Created April 26, 2014 18:42
Aegisub extradata usage
function foo(subs, sel, act)
local data = {"some", "random", "junk"}
for z, i in ipairs(sel) do
local l = subs[i]
l.extra.stuff = luabins.save(data)
subs[i] = l
end
for z, i in ipairs(sel) do
local l = subs[i]
local success, thedata = luabins.load(l.extra.stuff)
@nielsmh
nielsmh / readstl.py
Created January 26, 2015 19:18
EBU STL (Tech3264) file dumper
from struct import Struct
import sys
from collections import namedtuple
import codecs
def pick_header_codec(cpn):
return codecs.getdecoder(cpn)
class iso6937codec:
# Not a complete implementation, just good enough for basic testing
@nielsmh
nielsmh / login.php
Last active January 12, 2017 18:02 — forked from InukVT/login.php
$username = $_POST['username'];
$password = $_POST['password'];
$username = stripslashes($username);
$username = mysqli_real_escape_string($db, $username);
$sql = "SELECT * FROM users WHERE username='$username'";
$res = mysqli_query($db, $sql) or die(mysqli_error($db));
if (mysqli_num_rows($res) > 0)
{
$row = mysqli_fetch_assoc($res);
$hash = $row['password'];