Skip to content

Instantly share code, notes, and snippets.

View micalexander's full-sized avatar

Michael Alexander micalexander

View GitHub Profile
@micalexander
micalexander / add-fields-to-media-uploader.php
Last active December 25, 2015 03:19
wordpress:snippet:add fields to media uploader
<?php
/**
* Add fields to media uploader
*
* @param $form_fields array, fields to include in attachment form
* @param $post object, attachment record in database
* @return $form_fields, modified form fields
*/
function project_attachment_field_credit( $form_fields, $post ) {
@micalexander
micalexander / search.php
Created September 3, 2013 16:39 — forked from astockwell/search.php
wordpress:google-custom-search
<?php get_header(); ?>
<section>
<!-- Put the following javascript before the closing </head> tag. -->
<script>
(function() {
var cx = '000000000000000000000:aaa1aa1aa1a';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
@micalexander
micalexander / us-states.js
Created August 27, 2013 21:16
leaflet:u.s. state data for leaflet
var statesData = {"type":"FeatureCollection","features":[
{"type":"Feature","id":"01","properties":{"name":"Alabama","density":94.65},"geometry":{"type":"Polygon","coordinates":[[[-87.359296,35.00118],[-85.606675,34.984749],[-85.431413,34.124869],[-85.184951,32.859696],[-85.069935,32.580372],[-84.960397,32.421541],[-85.004212,32.322956],[-84.889196,32.262709],[-85.058981,32.13674],[-85.053504,32.01077],[-85.141136,31.840985],[-85.042551,31.539753],[-85.113751,31.27686],[-85.004212,31.003013],[-85.497137,30.997536],[-87.600282,30.997536],[-87.633143,30.86609],[-87.408589,30.674397],[-87.446927,30.510088],[-87.37025,30.427934],[-87.518128,30.280057],[-87.655051,30.247195],[-87.90699,30.411504],[-87.934375,30.657966],[-88.011052,30.685351],[-88.10416,30.499135],[-88.137022,30.318396],[-88.394438,30.367688],[-88.471115,31.895754],[-88.241084,33.796253],[-88.098683,34.891641],[-88.202745,34.995703],[-87.359296,35.00118]]]}},
{"type":"Feature","id":"02","properties":{"name":"Alaska","density":1.264},"geometry":{"ty
@micalexander
micalexander / pagination.php
Last active December 21, 2015 00:58
wordpress:pagination:snippet
<?php $args = array(
'base' => home_url() . '/news/%_%',
'format' => 'page/%#%/',
'total' => $wp_query->max_num_pages,
'current' => max( 1, $wp_query->query_vars['paged'] ),
'show_all' => true,
//'end_size' => 1,
//'mid_size' => 2,
'prev_next' => True,
'prev_text' => __('&larr; Previous'),
@micalexander
micalexander / wp-object.php
Last active December 21, 2015 00:08
wordpress:snippet:retrieve the currently-queried object.
<?php
$queried_object = get_queried_object();
echo "<pre>" ; var_dump($queried_object) ; echo "</pre>";
?>
@micalexander
micalexander / file_rename.sh
Created August 8, 2013 21:12
bash:search with in current directory and locate files that are not prefixed with an underscore and have an extension of .scss and, prefix with an underscore.
#!/bin/sh
proj_dir_arrays=( $(find . -name 'partials' -type d ) )
location=`pwd`
for proj_dir_array in "${proj_dir_arrays[@]}";
do
cd $location/${proj_dir_array/.\/}
shopt -s nullglob
@micalexander
micalexander / Gruntfile.js
Created August 5, 2013 02:03
grunt:copyto:snippet
copyto: {
stuff: {
files: [
{cwd: 'src/Dev/TaskBundle/Resources/public/', src: ['**/*'], dest: 'web/bundles/devtask/'}
],
options: {
processContent: function(content, path) {
// do something with content or return false to abort copy
return content;
},
@micalexander
micalexander / screenshots.js
Created July 8, 2013 22:49
phantomjs:casperjs:take multiple screenshots of different urls (dependencies: xcode, homebrew, phantomjs, casperjs)
// // Usage : casperjs filename.js
// // Size of the browser i.e. viewport
var view_width = 1024, view_height = 672;
// // Size of the clipped image
var clip_width = 1024, clip_height = 672;
var casper = require("casper").create({
// // Set the viewport size
@micalexander
micalexander / serialize_array.py
Created July 3, 2013 16:14
python:Takes multiple strings and serializes it for php
#! /usr/bin/python
weeks = [
('Monday','Tuesday','Wednesday','Thursday','Friday'),
('Monday','Tuesday','Wednesday','Thursday','Friday'),
('Monday','Tuesday','Wednesday','Friday'),
('Monday','Tuesday','Wednesday','Thursday','Friday'),
('Monday','Tuesday','Wednesday','Thursday','Friday'),
('Monday','Tuesday','Wednesday','Thursday','Friday'),
@micalexander
micalexander / wp-change-endpoint.php
Created May 23, 2013 17:16
wordpress:snippet:endpoint print
<?php
// Register "Print" Custom Endpoint, e.g. /listing/mylisting/print/ via http://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
function az_add_print_endpoint() {
add_rewrite_endpoint( 'print', EP_PERMALINK );
}
add_action( 'init', 'az_add_print_endpoint' );
function az_print_endpoint_redirect() {
global $wp_query;