Skip to content

Instantly share code, notes, and snippets.

View AndrewChamp's full-sized avatar
:octocat:
Web Application Developer / System Admin

Andrew Champ AndrewChamp

:octocat:
Web Application Developer / System Admin
View GitHub Profile
@AndrewChamp
AndrewChamp / docx_editor.php
Created July 27, 2015 15:05
Edit a Microsoft Word .docx file using PHP and the zip extension.
<?php
/**
* Edit a Word 2007 and newer .docx file.
* Utilizes the zip extension http://php.net/manual/en/book.zip.php
* to access the document.xml file that holds the markup language for
* contents and formatting of a Word document.
*
* In this example we're replacing some token strings. Using
* the Office Open XML standard ( https://en.wikipedia.org/wiki/Office_Open_XML )
* you can add, modify, or remove content or structure of the document.
@AndrewChamp
AndrewChamp / strip html comments.php
Created June 18, 2015 19:04
Regex for stripping HTML comments
<!--(?!<!)[^\[>].*?-->
<?php
$codes = Array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
@AndrewChamp
AndrewChamp / cache.feed.php
Created February 5, 2014 20:07
Downloads and caches content from Google's News RSS feed. This example is for sports.
<?php
$sports = 'https://news.google.com/news/feeds?ned=us&topic=s&output=rss';
$feedCache = 'feed.xml';
if(!file_exists($feedCache)):
fopen($feedCache, 'w');
$saveSports = file_get_contents($sports);
$saveSports = file_put_contents($feedCache, $saveSports);
elseif((time() - filemtime($feedCache)) > 3600):
$saveSports = file_get_contents($sports);
$saveSports = file_put_contents($feedCache, $saveSports);
@AndrewChamp
AndrewChamp / dancing-cat-bookmarklet.html
Last active December 23, 2015 05:08
Dancing Cat to any webpage. Bookmarklet.
<a href="javascript:(function(){ document.body.innerHTML += &quot;<img src='http://i.imgur.com/UhYgGxG.gif' style='display:block; position:fixed; bottom:-10px; left:50%; width:320px; height:407px; margin-left:-160px; z-index:9999;'>&quot;; })();">Dancing Cat!</a>
@AndrewChamp
AndrewChamp / jquery.scrollstick.js
Created August 22, 2013 17:00
How to use: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ setTimeout(function(){ $(".right.thirty").scrollstick(); },500); }); </script>
/*! jQuery.scrollstick (c) 2012, Rico Sta. Cruz. MIT License.
* https://github.com/rstacruz/jquery-stuff/tree/master/scrollstick */
// Makes something stick to the top when it gets scrolled away from.
//
// $("#nav").scrollstick();
//
// You may also specify options:
//
// $("#nav").scrollstick({
<?php
function seoName($title) {
return preg_replace('/[^a-z0-9_-]/i', '', strtolower(str_replace(' ', '-', trim($title))));
}
?>
<?php
/**
* No Image Options:
* 404 - do not load any image if none is associated with the email hash, instead return an HTTP 404 (File Not Found) response
* mm - (mystery-man) Simple, cartoon-style silhouetted outline of a person
* identicon - Geometric pattern based on an email hash
* monsterid - Generated 'monster' with different colors, faces, etc
* wavatar - Fenerated faces with differing features and backgrounds
* retro - 8-bit arcade-style pixelated faces
@AndrewChamp
AndrewChamp / replace-illegal-characters.php
Last active December 24, 2018 06:15
Replace illegal characters from file upload name.php
<?php
$bad = array_merge(array_map('chr', range(0,31)), array("<", ">", ":", '"', "/", "\\", "|", "?", "*", " "));
$result = str_replace($bad, "-", $filename);
?>
@AndrewChamp
AndrewChamp / Download website (scrapping)
Created June 25, 2013 16:10
# BASH -> Linux command prompt
wget -nc -nH -E -r -k -P /home/you/example.com -np http://example.com/