Skip to content

Instantly share code, notes, and snippets.

View cosmomathieu's full-sized avatar
🎯
Focusing

Cosmo Mathieu cosmomathieu

🎯
Focusing
View GitHub Profile
@dahnielson
dahnielson / UUID.php
Last active April 5, 2024 21:14
Pure PHP UUID generator
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4122 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.
@pamelafox
pamelafox / showspreadsheet.php
Created January 8, 2011 05:47
PHP for parsing the JSON output a published Google spreadsheet and displaying columns from each row.
<?php
// Parsing this spreadsheet: https://spreadsheets.google.com/pub?key=0Ah0xU81penP1dFNLWk5YMW41dkcwa1JNQXk3YUJoOXc&hl=en&output=html
$url = 'http://spreadsheets.google.com/feeds/list/0Ah0xU81penP1dFNLWk5YMW41dkcwa1JNQXk3YUJoOXc/od6/public/values?alt=json';
$file= file_get_contents($url);
$json = json_decode($file);
$rows = $json->{'feed'}->{'entry'};
foreach($rows as $row) {
echo '<p>';
@erkattak
erkattak / MY_Router.php
Created June 17, 2011 05:10
Using nested controllers in CodeIgniter 2.0
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* MY_Router allows the existence of controllers and controller sub directories of the same name
*
* @author Erik Straub
*/
class MY_Router extends CI_Router {
function __construct(){
parent::__construct();
@phred
phred / unserialize.php
Created September 7, 2011 19:04
Simple reliable and non-regex method to unserialize PHP session data
//
// This is the result of about an hour's delving into PHP's hairy-ass serialization internals.
// PHP provides a session_decode function, however, it's only useful for setting the contents of
// $_SESSION. Say, for instance, you want to decode the session strings that PHP stores in its
// session files -- session_decode gets you nowhere.
//
// There are a bunch of nasty little solutions on the manual page[1] that use pretty hairy regular
// expressions to get the job done, but I found a simple way to use PHP's unserialize and recurse
// through the string extracting all of the serialized bits along the way.
//
@michaelaguiar
michaelaguiar / MCAPI.class.php
Created October 7, 2011 21:20
PHP - MailChimp Class API
<?php
class MCAPI {
var $version = "1.3";
var $errorMessage;
var $errorCode;
/**
* Cache the information on the API location on the server
*/
var $apiUrl;
@mhawksey
mhawksey / gist:1276293
Last active October 23, 2023 09:00
Google App Script to insert data to a google spreadsheet via POST or GET - updated version as per https://mashe.hawksey.info/2014/07/google-sheets-as-a-database-insert-with-apps-script-using-postget-methods-with-ajax-example/
/*
Copyright 2011 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@yassiryahya
yassiryahya / functions.php
Created November 24, 2011 16:46
Assigning Role On Wordpress Registration & Profile Page
<?php
// Add two new role.
// Full list of capabilities can be found at http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table
add_role('writer', 'Writer', array(
'delete_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'read' => true,
@oodavid
oodavid / README.md
Last active April 6, 2024 18:45 — forked from aronwoost/README.md
Deploy your site with git

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@dieseltravis
dieseltravis / gist:2039843
Created March 14, 2012 21:56
progressive image loading
/*
HTML: (white-space and quotes in data attribute is important)
<noscript data-image='{ "large": { "src": "http://placehold.it/640x480", "width": "640", "height": "480", "highdpisrc": "http://placehold.it/1280x960" }, "small": { "src": "http://placehold.it/320x240", "width": "320", "height": "240", "highdpisrc": "http://placehold.it/640x480" }, "alt": "test image" }'>
<img src='http://placehold.it/160x120' width='160' height='120' alt='test image' />
</noscript>
*/
$(function () {
var selectedImage = ( $(window).width() >= 500 ) ? "large" : "small",
selectedSrc = ( window.devicePixelRatio >= 2 ) ? "highdpisrc" : "src";
@maxrice
maxrice / us-state-names-abbrevs.php
Created May 23, 2012 18:32
US State Names & Abbreviations as PHP Arrays
<?php
/* From https://www.usps.com/send/official-abbreviations.htm */
$us_state_abbrevs_names = array(
'AL'=>'ALABAMA',
'AK'=>'ALASKA',
'AS'=>'AMERICAN SAMOA',
'AZ'=>'ARIZONA',
'AR'=>'ARKANSAS',