Skip to content

Instantly share code, notes, and snippets.

Avatar

Arnold Daniels jasny

View GitHub Profile
@jasny
jasny / mysql_splitdump.sh
Last active May 30, 2023 07:23
Split MySQL dump SQL file into one file per table or extract a single table
View mysql_splitdump.sh
#!/bin/bash
####
# Split MySQL dump SQL file into one file per table
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump
####
if [ $# -lt 1 ] ; then
echo "USAGE $0 DUMP_FILE [TABLE]"
exit
@jasny
jasny / linkify.php
Last active February 6, 2023 22:39
PHP function to turn all URLs in clickable links
View linkify.php
<?php
/**
* Turn all URLs in clickable links.
*
* @param string $value
* @param array $protocols http/https, ftp, mail, twitter
* @param array $attributes
* @return string
*/
public function linkify($value, $protocols = array('http', 'mail'), array $attributes = array())
@jasny
jasny / tinytextindex.md
Last active July 6, 2021 22:23
TinyTextIndex
View tinytextindex.md

Tiny Text Index

Lightweight text indexer for PHP

Uses the dba extension (with db4)


Storing

Hello my name is Arnold and I'm not crazy. Arnold's kids are crazy though.

@jasny
jasny / class_casting.php
Created March 28, 2012 04:39
Class casting in PHP (very dirty, not for production)
View class_casting.php
<?php
/**
* Parent class
*/
class mother
{
protected $myvar;
function __construct($value)
@jasny
jasny / authhash.php
Created May 9, 2012 17:20
Authentication without sessions in PHP
View authhash.php
<?php
$secretword = "secret"; # Change this before use
$matches = null;
if (!empty($_REQUEST['AUTH']) && preg_match('/^(\w++):(\d++):(\w++)$/', $_REQUEST['AUTH'], $matches)) {
$username = str_rot13($matches[1]);
$time = (int)$matches[2];
$authhash = $matches[3];
$logged_in = md5($username . $time . $secretword) === $authhash && $time >= time() - 3000;
}
@jasny
jasny / .htaccess
Created May 30, 2012 14:53
Thumbnail creator in PHP
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ../thumb.php [QSA,L]
</IfModule>
@jasny
jasny / gist:3766751
Created September 22, 2012 16:55
Logitech Performance Mouse MX - thumb button as middle-mouse
View gist:3766751
#!/bin/bash
for ID in $(xinput list | grep "Logitech Unifying Device" | perl -pe 's/^.*?id=(\d+).*$/\1/'); do
xinput set-button-map $ID 1 2 3 4 5 6 7 8 9 2 11 12 13 14 15 16 17 18 19 20 2>/dev/null | true;
done
@jasny
jasny / gist:3766752
Created September 22, 2012 16:56
Bash Aliases
View gist:3766752
function mvdown { mv "$1" /tmp/_mvdown_; rmdir $(dirname "$1"); mv /tmp/_mvdown_ $(dirname "$1"); }
@jasny
jasny / Autoloader.php
Created October 19, 2012 14:38
Autoloader for PHP
View Autoloader.php
<?php
/**
* A very simple autoloader
*/
class Autoloader
{
/**
* Only use this class statically.
* @ignore
@jasny
jasny / image-embed-html.php
Created October 23, 2012 10:40
Create base64 encoded image to embed in HTML
View image-embed-html.php
<?php
$files = array_slice($argv, 1);
foreach ($files as $file) {
$picture = file_get_contents($file);
$size = getimagesize($file);
// base64 encode the binary data, then break it into chunks according to RFC 2045 semantics
$base64 = chunk_split(base64_encode($picture));