Skip to content

Instantly share code, notes, and snippets.

View ajschlosser's full-sized avatar

Aaron John Schlosser ajschlosser

  • California
View GitHub Profile
<?php
function get_halves ($a) {
$total_length = 0;
for($i = 1; $i <= count($a); $i++) {
$total_length += strlen($a[$i]);
}
echo "Cutting an array of ".count($a)." strings totaling ".$total_length." characters in half:<br><br>";
$first_half_length = 0;
$second_half_length = 0;
function put_in_paragraph ($p) { return "<p>" . $p . "</p>"; }
function print_halves ($a) {
$total_length = 0;
for($i = 1; $i <= count($a); $i++) {
$total_length += strlen($a[$i]);
}
$first_half_length = 0;
$second_half_length = 0;
$second_half_index = 0;
$done = false;
@ajschlosser
ajschlosser / ACF_make_two_columns
Last active August 29, 2015 14:06
Breaks an ACF field into two divs of evenish columns
<?php
/**
*
* Breaks an ACF field into two divs of evenish columns
*
* @author Aaron John Schlosser <aaron@aaronschlosser.com>
* @link https://gist.github.com/ajschlosser/daf17648f0f42d1597ec#file-acf_make_two_columns
* @copyright Copyright 2014 Aaron John Schlosser
* @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
@ajschlosser
ajschlosser / print_wp_nav_menu
Last active August 29, 2015 14:06
Wraps iterated wp_get_nav_menu_items output in customizable HTML
function print_wp_nav_menu ($menu, $params=array()) {
/**
*
* Wraps iterated wp_get_nav_menu_items output in customizable HTML
*
* @author Aaron John Schlosser <aaron@aaronschlosser.com>
* @link https://gist.github.com/ajschlosser/daf17648f0f42d1597ec#file-acf_make_two_columns
* @copyright Copyright 2014 Aaron John Schlosser
* @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2
* @param array $params Array containing all other parameters (optional)
@ajschlosser
ajschlosser / gulpfile-basic-webdev
Last active August 29, 2015 14:06
A very basic gulpfile.js for web development (with Jade and PHP support).
/*
* Base Gulp.js workflow
* for simple front-end projects
* author: Aaron John Schlosser
* url: http://www.aaronschlosser.com
*/
var gulp = require("gulp"),
gutil = require("gulp-util"),
concat = require("gulp-concat"),
@ajschlosser
ajschlosser / compass.js
Created September 10, 2014 21:42
A fix for using Gulp with Compass. This will prevent gulp-compass from rendering identical sprites/images every time it runs. Replaces compass.js.
'use strict';
var PLUGIN_NAME = 'gulp-compass',
spawn = require('child_process').spawn,
gutil = require('gulp-util'),
path = require('path'),
which = require('which').sync,
defaults = {
style: false,
comments: true,
@ajschlosser
ajschlosser / divSlider.js
Created September 17, 2014 22:03
A quick fix for fading slides. Will cycle through <div> elements with the class "ds-slide" and apply the class "ds-faded" to them at predefined intervals. The "ds-faded" class can then by styled with transitions of your choice.
// Slides
var divSlider = function () {
var ds = this;
var transitionClass = "ds-faded";
ds.n = 0;
ds.pause = function () { clearInterval(ds._intervalId); }
ds.toggle = function () {
console.log(ds.n, ds.slides.length-1);
ds.n < ds.slides.length-1 ? ds.n++ : ds.n = 0;
var prev = ds.n;
@ajschlosser
ajschlosser / Vagrantfile
Last active August 29, 2015 14:11
Basic Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
/**
* Checks to see if a given string ends with a particular file extension
* @param {string} f String representing a possible file name with extension
* @param {string} e The sought extension
* @returns {boolean}
*/
function hasExtension (f, e) {
if (e[0] !== '.') {
e = '.' + e;
}
@ajschlosser
ajschlosser / addressGenerator
Created February 23, 2015 17:38
Generates a random, generic, US-style address.
function generateAddress (obj) {
var odds = Math.floor(Math.random() * 999) + 1,
multiplier = '',
streetLength = Math.floor(Math.random() * 5 + 1),
streetNumber = '',
apartmentTypes = ['Unit', 'Apt.', 'Suite'],
apartmentLetters = ['A','B','C','D','E','F','G'],
apartmentLetter = '',
apartmentType = '',
apartmentNumber = '',