Skip to content

Instantly share code, notes, and snippets.

View gavinblair's full-sized avatar

Gavin Blair gavinblair

View GitHub Profile
<?php
// In order to put <sup></sup> tags in the format string,
// you have to escape all letters that are in
// http://php.net/manual/en/function.date.php
echo date('F j<\s\up>S</\s\up> Y', $timestamp);
?>
@gavinblair
gavinblair / nodetitle_and_menutitle.sql
Created July 20, 2010 14:19
Drupal 6: Get node titles and menu titles from all nodes of a type.
SELECT node.title, node.nid, menu_links.link_title FROM node
LEFT JOIN menu_links ON (link_path = CONCAT('node/', node.nid))
WHERE node.type = 'page'
<?php
//ini_set("display_errors","on");
//***************
//
//Author: Andrew McClenaghan / Echidna Solutions Corp.
//Date: August 3, 2010
//
//***************
@gavinblair
gavinblair / date.sql
Created September 1, 2010 16:03
Convert timestamp to readable date right in MySQL
SELECT date_format(FROM_UNIXTIME(u.access), '%Y %M %D') FROM users u ORDER by u.access DESC;
@gavinblair
gavinblair / conditions.php
Created September 2, 2010 14:13
Reversing the order of a condition to avoid hard-to-find assignment problems
<?php
//This is what I normally do:
if($something == "string") { ... }
//The problem is, if I accidentally miss an = then it would be an assignment!
if($something = "string") { /* uh oh! */ }
//To prevent this, get in the habit of reversing the order:
if("string" == $something) { ... }
$.ajax({
url: '/myphpajaxpath',
type: 'post',
data: 'postvar=1&postvar2=2&postvarthree=3',
succes: function(msg) {
alert("yay!"+msg);
},
error: function(msg) {
console.log("An error occurred: "+msg);
}
@gavinblair
gavinblair / listing.html
Created September 20, 2010 22:00
Adding a year ribbon to thumbnails with PHP and GD
<div class="film">
<div class="imgbox">
<div style="background-image: url(ribbon.php?text=2010)" class="year">
</div>
<img height="151" width="200" alt="In tellus" src="robot1.gif" />
</div>
<h4><a href="/in-tellus-libero">In tellus libero</a></h4>
<p>In tellus libero, pretium et rhoncus ut, fringilla et enim. Duis at dolor non dolor ultricies…</p>
</div>
-- phpMyAdmin SQL Dump
-- version 3.2.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 26, 2010 at 09:43 PM
-- Server version: 5.1.44
-- PHP Version: 5.3.2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
$("input[type=text]").each(function(){
if($(this).attr("title").length > 0) {
//do the thing, to $(this)
}
});
@gavinblair
gavinblair / mymodule.module
Created September 30, 2010 21:26
Multilingual Module Pages in Drupal
<?php
function mymodule_menu(){
$languages = language_list('enabled');
$items = array();
foreach ($languages[1] as $lang) {
$items[t('my_path', array(), $lang->language)] = array(
'title' => t('Page Title', array(), $lang->language),
'page callback' => 'pagefunction',