Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
ChrisLTD / gist:5332850
Last active December 15, 2015 22:28
Lessn TextExpander Snippet
set api_key to "xxxxxxxxx"
set domain to "yourdomain.net"
set the longURL to (the clipboard as string)
if ((characters 1 through 4 of longURL as string) is not "http") then
return "Not a valid URL"
else
set shellScript to ("curl --url \"http://" & domain & "/-/?api=" & api_key & "&url=" & longURL & "\"")
set shortURL to (do shell script shellScript)
@ChrisLTD
ChrisLTD / vcard_export_action.py
Created March 22, 2013 20:17
Django Admin export selection as vCard action
from django.http import HttpResponse
from datetime import datetime
def export_as_vcard(modeladmin, request, queryset):
"""
Export vCard admin action
Update source to match your model
Example usage:
@ChrisLTD
ChrisLTD / gist:4061876
Created November 12, 2012 21:03
Check to see if Wordpress post is in custom taxonomy category
function in_custom_category_slug($post_id, $taxonomy, $category_slug){
$categories = get_the_terms($post_id, $taxonomy);
foreach ($categories as $category) {
if($category->slug == $category_slug){
return true;
}
}
return false;
}
@ChrisLTD
ChrisLTD / append_GET_string_to_iframe.js
Created November 9, 2012 17:15
Append GET variables in URL to iframe on the page
var strQueryString="";
var hasQueryString = document.URL.indexOf('?');
if (hasQueryString != -1){
strQueryString = document.URL.substring(hasQueryString, document.URL.length);
}
if(strQueryString != ""){
iframe = document.getElementById("IFRAME_ID_HERE");
currentSrc = iframe.getAttribute('src');
@ChrisLTD
ChrisLTD / wp_social_media_widget.php
Created October 31, 2012 19:24
Wordpress: Displays social media links in an unstyled list
<?php
/*
Plugin Name: Social Media Link Widget
Plugin URI: http://chrisltd.com
Description: Displays social media links in an unstyled list
Author: Chris Johnson
Version: 1
Author URI: http://chrisltd.com
*/
@ChrisLTD
ChrisLTD / gist:3924562
Created October 20, 2012 19:56
Drupal 7 image gallery output
// Requires Content Type with image field with multiple images as described here: http://drupal.stackexchange.com/a/5901
// Title is output as caption if there is title text
// Image size is determined by custom image style in Drupal admin named "gallery_thumb"
<?php
$gallery_images = $node->field_gallery_image['und'];
for($i = 0; $i < count($gallery_images); $i++) {
$image = $gallery_images[$i];
$output = '<a href="' . file_create_url($image['uri']) . '">';
$output .= '<img src="' . image_style_url("gallery_thumb", $image['uri']) . '">';
@ChrisLTD
ChrisLTD / WordpressTimeline.php
Created August 21, 2012 18:21
Wordpress Timeline using custom content type
<?php
// 1. Put all timeline entries into array
$timeline_entries = array();
// Retrieve entries sorted by date
$query = new WP_Query( array('post_type' => 'timeline-entry', 'posts_per_page' => -1, 'order' => 'ASC' , 'orderby' => 'meta_value', 'meta_key' => 'date' ));
if ($query->have_posts()):
while ( $query->have_posts() ):
$query->the_post();
$date = get_custom_field('date');
@ChrisLTD
ChrisLTD / 1-tablemarkup.html
Created April 26, 2012 14:37 — forked from paulirish/1-tablemarkup.html
whitespace use for html/css readability
<!-- formatting fun #1: tables! -->
<!-- use whitespace to mimic the layout you want. leave off optional end tags for readability -->
<table>
<caption>Selector engines, parse direction</caption>
<thead>
<tr><th>Left to right <th>Right to left
<tbody>
<tr><td>Mootools <td>Sizzle
@ChrisLTD
ChrisLTD / functions.php
Created July 22, 2011 17:11
Create Wordpress widget that outputs shortcode
<?
function sidebarbrief_func($atts) {
extract(shortcode_atts(array('foo' => 'something'), $atts));
global $more; // Declare global $more (before the loop).
$posts_query = new WP_Query( array( 'post_type' => array('brief'), 'tag_id' => 16, posts_per_page => 1 ) );
$output = '<h1>News in Brief</h1>';
while ( $posts_query->have_posts() ) : $posts_query->the_post();
$more = 0; // Set (inside the loop) to display content above the more tag.
$output .= '<div class="brief">';
@ChrisLTD
ChrisLTD / functions.php
Created May 24, 2011 14:54
Enable Kitchen Sink in Wordpress TinyMCE by default
function unhide_kitchensink( $args ) {
$args['wordpress_adv_hidden'] = false;
return $args;
}
add_filter( 'tiny_mce_before_init', 'unhide_kitchensink' );