Skip to content

Instantly share code, notes, and snippets.

View jackreichert's full-sized avatar

Jack Reichert jackreichert

View GitHub Profile
@jackreichert
jackreichert / make_dir
Last active August 29, 2015 14:21
Recursively make a directory in php
// helper method
function make_dir( $path, $permissions = 0777 ) {
return is_dir( $path ) || mkdir( $path, $permissions, true );
}
// for use inline
if ( ! file_exists( $path ) ) {
mkdir( $path, 0777, true );
}
@jackreichert
jackreichert / getKeyVals
Last active March 19, 2020 07:12
This is a swift extension for NSURL so you can parse the query string and get back a dictionary of the variables.
extension NSURL {
func getKeyVals() -> Dictionary<String, String>? {
var results = [String:String]()
var keyValues = self.query?.componentsSeparatedByString("&")
if keyValues?.count > 0 {
for pair in keyValues! {
let kv = pair.componentsSeparatedByString("=")
if kv.count > 1 {
results.updateValue(kv[1], forKey: kv[0])
}
(function($) {
$(document).ready(function(e){
e.preventDefault();
$('input[name=titleSubmit]').click(function(){
$.ajax({
type: "GET",
url: SSL_Ajax.ajaxurl,
cache: false,
dataType: "jsonp",
crossDomain: true,
@jackreichert
jackreichert / add_class_to_menu_items
Created July 25, 2013 23:53
This is how you add a class to menu items in WordPress. Change the "theme_location" to == "primary" to any menu name you like. Or remove the condition to have it applied everywhere.
add_filter( 'wp_nav_menu_objects', 'add_menu_class', 10, 2 );
function add_menu_class( $sorted_menu_items, $args ) {
if ($args->theme_location == "primary")
foreach ($sorted_menu_items as $i => $menu )
$sorted_menu_items[$i]->classes[] = 'color-'.strtolower(str_replace(' ', '-', $menu->post_title));
return $sorted_menu_items;
}
@jackreichert
jackreichert / _.md
Created July 21, 2013 00:09
Jess' Chronoglyph
@jackreichert
jackreichert / WordPress Setup
Last active December 18, 2015 20:38
What to run after installing WordPress to set file permissions and ownership.
chown -R apache:apache .
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
@jackreichert
jackreichert / exportcsv.php
Created May 24, 2013 16:29
write csv with fputcsv() directly to php://output
$filename="export.csv";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$csv = fopen('php://output', 'w');
foreach($rows as $ind=>$row){
if($ind==0)
fputcsv($csv,array_keys($row));
@jackreichert
jackreichert / inputtitle_submit.js
Last active September 26, 2020 15:03
Example showing how to use AJAX in WordPress
(function ($) {
$(document).ready(function () {
$('#next').click(function () {
$.post(
PT_Ajax.ajaxurl,
{
// wp ajax action
action: 'ajax-inputtitleSubmit',
// vars
@jackreichert
jackreichert / document.xml
Last active May 25, 2022 15:18
Convert Docx XML to HTML
<?xml version="1.0" encoding="UTF-8"?>
<w:document xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"
@jackreichert
jackreichert / jquery.activatePlaceholders.js
Created March 1, 2012 21:50
Polyfill for the Input "Placeholder" Attribute.
function activatePlaceholders() {
var detect = navigator.userAgent.toLowerCase();
if (detect.search("msie") > 0 ) {
$('input[type=text],input[type=email]').each(function(ind,elem) {
if ($(elem).attr('placeholder') != ""){
$(elem).val($(elem).attr("placeholder"));
$(elem).click(function() {
if ($(this).val() == $(this).attr("placeholder")) {
$(this).val("");