Skip to content

Instantly share code, notes, and snippets.

View MauMaGau's full-sized avatar

Dave Townsend MauMaGau

View GitHub Profile
@MauMaGau
MauMaGau / gist:2301132
Created April 4, 2012 13:45
PHP: date to age
<?php
/* Date to Age */
if(
isset ($data['day']) && isset($data['month']) && isset($data['year']) &&
is_numeric($data['day']) &&
is_numeric($data['month']) &&
is_numeric($data['year'])
){
@MauMaGau
MauMaGau / gist:2301137
Created April 4, 2012 13:45
PHP: time ago
<?php
/* Time ago */
$timestamp = 1332686482; // a unix timestamp
$t = array('year'=>31556926,'month'=>2629744,'week'=>604800,'day'=>86400,'hour'=>3600,'minute'=>60,'second'=>1);
// Calculate how long ago the timestamp is
$diff = time() - $timestamp;
@MauMaGau
MauMaGau / gist:2301153
Created April 4, 2012 13:46
PHP: GeoNames class
<?php
/* GeoCode class */
// Usage
$Geonames = new Geonames();
print_r( $Geonames->geocode_postcode('SW1A 0AA','username') );
if( ! empty($Geonames->message) ){
echo $Geonames->message;
@MauMaGau
MauMaGau / gist:2301194
Created April 4, 2012 13:48
PHP/JS: Codeigniter Ajax
<?php
/* CI AJAX */
public function index( $output_type ){
// the main controller logic...
switch( $output_type ){
@MauMaGau
MauMaGau / gist:2579290
Created May 2, 2012 19:02
CI: video upload (dump)
<?php
public function upload( $gallery_id , $ajax = FALSE ){
// Check if a user of any level is logged in
if( $this->require_min_level(1) ){
$file_input = 'userfile[]';
$config['encrypt_name'] = TRUE;
$config['upload_path'] = $this->config->item('user_upload_folder').'working/';
$config['storage_path'] = $this->config->item('user_upload_folder');
@MauMaGau
MauMaGau / gist:2579325
Created May 2, 2012 19:05
HTML/CI: video upload
<section id='upload-media'>
<h3 class='clickable'>Upload Media</h3>
<section id='file-uploader'>
<p>Max total file size: 200mb</p>
<input type='hidden' name='gallery_id' value='<?php echo $gallery->gallery_id; ?>' />
<noscript>
<?php echo form_open_multipart('gallery/upload/'.$gallery->gallery_id);?>
<input type="hidden" name="max_file_size" value="209715200" />
<input type="file" name="userfiles" />
@MauMaGau
MauMaGau / gist:2579345
Created May 2, 2012 19:06
JQuery: qqFileUploader video upload
$(function() {
var base_url = $('base').attr('href');
gallery_id = $('input[name=gallery_id]').val();
/* Uploader */
var uploader = new qq.FileUploader({
@MauMaGau
MauMaGau / gist:2579601
Created May 2, 2012 19:34
PHP: video conversion script
<?php
// Run from the command line, so we'll grab arguments from there
// input arguments: 0=>script, 1=>file_name, 2=>temp_file
$file_name = $argv[1];
$temp_file = $argv[2];
$uploads = '/opt/lampp/htdocs/user_uploads/';
// Set up file location strings
@MauMaGau
MauMaGau / gist:2583140
Created May 3, 2012 04:19
PHP:CI:lib HexWheel
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
@author: dtownsend@gmail.com / http://dtownsend.co.uk
A hex-based colour converter.
Currently only supports altering brightness and saturation.
*/
class HexWheel{
@MauMaGau
MauMaGau / gist:2831080
Created May 29, 2012 22:04
AJAX: Non-blocking
<?php
// If this is an ajax call, just return what's needed
if(isset($_POST['ajax'])){
sleep(2); // Add some lag
echo $_POST['value']; // The input message
}else{
?>
<html>
<head>