Skip to content

Instantly share code, notes, and snippets.

View ziadoz's full-sized avatar

Jamie York ziadoz

View GitHub Profile
@ziadoz
ziadoz / embed.php
Last active December 16, 2015 07:19
Parsing YouTube Embed Markup Using DOMDocument
<?php
function parse_youtube_embed($embed) {
if (empty($embed)) {
return false;
}
$dom = new DOMDocument;
if (! $dom->loadHTML($embed)) {
return false;
}
@ziadoz
ziadoz / ContainsHtml.php
Last active December 16, 2015 08:59
Symfony Custom Form Basic Spam Validators
<?php
namespace Ziadoz\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class ContainsHtml extends Constraint
{
@ziadoz
ziadoz / extends.js
Created April 23, 2013 19:25
jQuery Extends
$.fn.extend({
// ---- HTML Comments ---- //
comments: function() {
return $(this).contents()
.filter(function() {
return this.nodeType == 8;
});
},
// ---- Outer HTML ---- //
@ziadoz
ziadoz / compslug.class.php
Last active December 17, 2015 19:59
Perch Composite Slug Field Type
<?php
/**
* Composite Slug Field Type.
*
* File: PERCH_PATH/addons/fieldtypes/compslug/compslug.class.php
* Usage: <perch:content id="slug" type="compslug" for="lastname firstname" suppress="true" />
* @author Jamie York
**/
class PerchFieldType_compslug extends PerchFieldType
{
@ziadoz
ziadoz / restore.sql
Last active December 18, 2015 08:19
Perch: Restore Records
-- Update record revision numbers for a region, so they display in Perch.
-- Replace :regionID and :revisionNum
UPDATE perch2_content_items pci
INNER JOIN
(
SELECT
itemID,
MAX(itemRev) AS itemRevMax
FROM perch2_content_items
@ziadoz
ziadoz / vanilla.sql
Last active December 21, 2015 02:09
Mass Delete Vanilla Forum Spam Users
-- Delete Spammers.
delete from GDN_User where ((CountDiscussions = 0 and CountComments = 0) or About != '' or Name = '[Deleted User]') and Admin = 0;
delete from GDN_User where CountVisits = 0 and Admin = 0;
delete from GDN_UserRole where UserID not in (select UserID from GDN_User);
-- Cleanup Data.
delete from GDN_Discussion where InsertUserID not in (select UserID from GDN_User);
delete from GDN_Comment where InsertUserID not in (select UserID from GDN_User);
delete from GDN_UserDiscussion where UserID not in (select UserID from GDN_User);
delete from GDN_Session where UserID not in (select UserID from GDN_User);
@ziadoz
ziadoz / icu.php
Last active December 21, 2015 14:48
PHP NumberFormatter and ICU Decimal Patterns
<?php
// ICU Decimal Patterns:
// http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details
$price = 1560.52;
$formatter = new NumberFormatter('en_CA', NumberFormatter::CURRENCY);
// Default ICU Decimal Pattern:
echo $formatter->getPattern(); // ¤#,##0.00;(¤#,##0.00)
echo $formatter->format($price); // $1,560.52
@ziadoz
ziadoz / .htaccess
Created September 5, 2013 17:50
Apache rewrite non-www to www and vice versa.
RewriteEngine On
RewriteBase /
# Rewrite: non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [R=301,L]
# Rewrite: www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}$1 [R=301,L]
@ziadoz
ziadoz / gmvault-unzip.rb
Last active December 24, 2015 16:38
Unzip GMVault Compressed Emails
#!/usr/bin/env ruby
# GMVault: http://gmvault.org/
# Unzips GMVault compressed emails (.eml.gz).
# Enter an absolute path, e.g., /Users/Username/gmvault-db/db
print 'Enter the directory path containing the zip files: '
path = STDIN.gets.chomp.chomp('/')
path = path + '/**/*.eml.gz'
@ziadoz
ziadoz / iframe.html
Last active December 24, 2015 16:39
Auto Resize iFrame (Same Origin)
<!DOCTYPE HTML>
<html>
<head>
<title>iFrame</title>
</head>
<body>
<!-- Page Content -->
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>