Skip to content

Instantly share code, notes, and snippets.

View gavinblair's full-sized avatar

Gavin Blair gavinblair

View GitHub Profile
@gavinblair
gavinblair / labels.css
Created October 20, 2010 17:09
Adds : after labels and * after required labels
/* Adds : after labels */
form label:after{
content:":";
}
/* Adds * after required labels */
form label.required:after{
content:"*";
}
@gavinblair
gavinblair / date_sub.sql
Created October 27, 2010 16:35
select rows with timestamp within the last 30 days
SELECT * FROM mytable WHERE timestamp > DATE_SUB(NOW(), INTERVAL 30 day);
@gavinblair
gavinblair / wrapping_if.php
Created November 18, 2010 18:52
Which method is better?
<?php
function myfunction(){
if($somecondition) {
...
... //many lines of code
...
} else {
return false;
}
$('fieldset.collapsible:not(.tao-processed) > legend > .fieldset-title').each(function() {
var fieldset = $(this).parents('fieldset').eq(0);
fieldset.addClass('tao-processed');
// Expand any fieldsets containing errors.
if ($('input.error, textarea.error, select.error', fieldset).size() > 0) {
$(fieldset).removeClass('collapsed');
}
// Add a click handler for toggling fieldset state.
$(this).click(function() {
if (fieldset.is('.collapsed')) {
<?php
//updated to fit http://drupal.org/writing-secure-code
function ajax_autocomplete(){
$q = $_GET['z'].'%';
$limit = intval($_GET['limit']);
$sql = "select distinct title from node where status = 1 AND (type = 'product' OR type = 'model_documentation') AND title LIKE '%s' order by title limit %d";
$result = db_query($sql, $q, $limit);
while($row = db_fetch_array($result)) {
echo "{$row['title']}\n";
@gavinblair
gavinblair / citybudget.js
Created December 6, 2010 00:29
Example implementation of the city budget API using JSONP
//It involves two steps -- the ajax call and the call back function:
$.ajax({
url:'http://budget.opendatalondon.ca/api/budget/year/2010/org/803/format/jsonp',
type:'GET',
dataType:'jsonp',
success: abc
});
//the JSON is passed as a parameter to your callback function
function abc(budget){
@gavinblair
gavinblair / rtrim.php
Created January 10, 2011 23:22
lose the last comma off a list
<?php
$sql = "UPDATE coupons SET ";
foreach($args as $key => $arg) {
$arg = $this->db->escape($arg);
$key = $this->db->escape($key);
$sql .= "$key = $arg, ";
}
//lose the last comma
$sql = rtrim($sql, ", ");
@gavinblair
gavinblair / minetweet.php
Created January 21, 2011 22:29
script that periodically checks the minecraft server log, and tweets when players log in/out
<?php
//run via cron every 2 minutes
//Get the log file
$log = file_get_contents("/opt/minecraft/server.log");
$log = explode("\n", $log);
$loggedinusers = array();
//only look at lines that mention logging in or logging out
@gavinblair
gavinblair / case-sensitive-like.sql
Created February 28, 2011 20:04
Case Sensitive LIKE in MySQL
// this returns 1 (true)
select 'A' like 'a'
// this returns 0 (false)
select 'A' like binary 'a'
//from http://www.delphifaq.com/faq/databases/mysql/f801.shtml
@gavinblair
gavinblair / msg.php
Created March 4, 2011 20:11
Minecraft Server Message command
<?php
unset($argv[0]);
$message = implode(" ", $argv);
shell_exec("curl -d '{\"name\":\"SERVER\",\"message\":\"$message\"}' http://10.0.1.104:80/up/sendmessage");