Skip to content

Instantly share code, notes, and snippets.

View jasny's full-sized avatar

Arnold Daniels jasny

View GitHub Profile
@jasny
jasny / HTMLToXMLFilter.php
Created June 26, 2014 10:41
Stream filter to convert HTML5 to XML
<?php
/**
* Stream filter to convert HTML5 to XML.
*
* <code>
* $dsn = "php://filter/read=htmltoxml/resource=" . $url;
* $xml = XMLReader::open($dsn);
* </code>
*
#!/bin/sh
OLD_DB=$1
NEW_DB=$2
TABLES=`echo "SHOW TABLES IN $1;" | mysql -NB`
IFS="
"
@jasny
jasny / flip.js
Created March 27, 2014 13:32
Turn text upside down with JavaScript
//this script is based on coding by Reverse Fad http://www.revfad.com
function flip() {
var result = flipString(document.f.original.value.toLowerCase());
document.f.flipped.value = result;
}
function flipString(aString) {
var last = aString.length - 1;
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
var c = aString.charAt(i)
@jasny
jasny / bootstrap-em.less
Last active January 5, 2020 15:36
Use em or rem font-size in Bootstrap 3
/**
* Use em or rem font-size in Bootstrap 3
*/
@font-size-root: 14px;
@font-unit: 0rem; // Pick em or rem here
// Convert all variables to em
@jasny
jasny / 000-default.conf
Last active August 29, 2015 13:56
Apache2 localhost
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/arnold/Projects/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/arnold/Projects/>
Options Indexes FollowSymLinks
@jasny
jasny / install-git-hooks
Last active January 2, 2016 22:59
Define git hooks within your repository. Allows defining multiple scripts for one hook.
#!/bin/bash
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc"
HOOK_DIR=$(git rev-parse --show-toplevel)/.git/hooks
DIR=$(dirname "$0")
for hook in $HOOK_NAMES; do
# If the hook already exists, is executable, and is not a symlink
if [ ! -h "$HOOK_DIR/$hook" -a -x "$HOOK_DIR/$hook" ]; then
mv "$HOOK_DIR/$hook" "$HOOK_DIR/$hook.local"
fi
@jasny
jasny / .htaccess
Last active December 28, 2015 07:59
URL shortener
RewriteEngine On
RewriteRule ^(\w{5})$ /index.php?key=$1
@jasny
jasny / gopenvpn.sh
Last active December 13, 2015 16:58
GTK interface to start openvpn
#!/bin/bash
CONFIG=$(zenity --file-selection --file-filter='*.opvn' --title="Select openvpn config file")
[ -n "$CONFIG" ] || exit 1
cd $(dirname "$CONFIG")
gksudo /usr/sbin/openvpn $CONFIG
@jasny
jasny / image-embed-html.php
Created October 23, 2012 10:40
Create base64 encoded image to embed in HTML
<?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));
@jasny
jasny / Autoloader.php
Created October 19, 2012 14:38
Autoloader for PHP
<?php
/**
* A very simple autoloader
*/
class Autoloader
{
/**
* Only use this class statically.
* @ignore