Skip to content

Instantly share code, notes, and snippets.

View pietvanzoen's full-sized avatar

Piet van Zoen pietvanzoen

View GitHub Profile
@pietvanzoen
pietvanzoen / Numberstowords.php
Created July 8, 2013 17:05
Numbers to words :: A php library for converting numbers to words. Useful for bio copy that includes years since an event. Also useful for dynamically rendering grid systems that use words such as class="columns six". #php
<?php
// Goes in codeigniter/libraries
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Numbertowords {
function convert_number($number) {
if (($number < 0) || ($number > 999999999)) {
@pietvanzoen
pietvanzoen / array_group.php
Created July 8, 2013 17:10
Array_group :: Divide an array into groups. #php
<?php
/**
* Returns an array of arrays.
*
* $array - an array to be divided
* $groups - number of groups to divide the array into
*/
function array_group($array, $groups)
{
@pietvanzoen
pietvanzoen / placeholders.php
Created July 8, 2013 17:11
Image Placeholders :: Helper functions for placeholder image services such as http://Placehold.it and http://Placekitten.com. #php
<?php
// http://placehold.it
function placeholdit($width = 100, $height = '', $text = '', $colors = '')
{
$dimentions = $width.( !empty($height) ? 'x'.$height : '');
$text = !empty($text) ? '&text='.urlencode($text) : '';
$colors = !empty($colors) ? explode(' ', $colors) : '';
$colors = !empty($colors) ? '/'.$colors[0].'/'.$colors[1] : '';
return 'http://placehold.it/'.$dimentions.$colors.$text;
}
@pietvanzoen
pietvanzoen / get_excerpt_stripped.php
Created July 9, 2013 20:35
Get_excerpt_stripped :: Record model method for Fuelcms modules to look for record excerpt, strip tags and set character. If no excerpt is found record content is used instead. #fuel
<?php
function get_excerpt_stripped($char_limit = NULL)
{
$this->_CI->load->helper('text');
$excerpt = (empty($this->excerpt)) ? $this->content : $this->excerpt;
// must strip tags to get accruate character count
$excerpt = strip_tags($excerpt);
if (!empty($char_limit))
{
@pietvanzoen
pietvanzoen / assume-unchanged.sh
Created July 9, 2013 22:09
Assume Unchanged :: Set a file as assume unchaged. Different to .gitignore. A file which is assumed unchanged can be in the repo but local changes aren't tracked. Handy for .htaccess or other config files. #git
#!/bin/bash
# from repo root foder
git update-index --assume-unchanged <file>
# or
git update-index --no-assume-unchanged <file>
@pietvanzoen
pietvanzoen / extend.less
Last active December 19, 2015 14:09
LESS Extend :: #css
/** EXAMPLE 1
---------------------------------------- **/
/* LESS */
.museo,h1,h2,h3 {
font-family:"Museo",sans-serif;
}
.nav {
/* some css */
&:extend(.museo);
@pietvanzoen
pietvanzoen / fuel_migrate.sh
Created July 16, 2013 23:11
Fuel Migrate Command :: Terminal command to run fuel's migration command. More info here: http://docs.getfuelcms.com/general/migrations #fuel
# update fuel to latest migration
php index.php fuel/migrate/latest
@pietvanzoen
pietvanzoen / smooth_animation.css
Created July 19, 2013 22:12
Smooth Animations :: Force hardware acceleration on elements for better animation rendering. #css
.smooth_animation { -webkit-transform: translate3d(0,0,0); -moz-transform: translate3d(0,0,0); -ms-transform: translate3d(0,0,0); -o-transform: translate3d(0,0,0); transform: translate3d(0,0,0);}
@pietvanzoen
pietvanzoen / find_next_nav_item.php
Last active December 20, 2015 07:59
Find Next Array Item :: This function will find the next item in an array. Useful for dynamically generating a nav link for the next sibling page based on the $nav array. #fuel
<?php
function find_next($array, $search, $key, $loop = false)
{
// $array = array to search
// $search = string to search against, e.g. current uri_string()
// $key = array key to compare $search against
// $loop = if set to TRUE will return first value if it reaches the end of the array
@pietvanzoen
pietvanzoen / array_vals_sorter.php
Created August 29, 2013 19:09
Array Values Sorter :: Sort a multi dimensional array by values based on key. #php
<?php
function array_vals_sorter($array, $val_key, $order = 'asc') {
$sorter = array();
foreach ($array as $key => $row)
{
$sorter[$key] = $row[$val_key];
}
array_multisort($sorter, SORT_ASC, $array);
if ($order != 'asc') $array = array_reverse($array,TRUE);