Skip to content

Instantly share code, notes, and snippets.

Avatar

Raphaël Riel raphael-riel

  • Québec, QC, Canada
View GitHub Profile
View IAM_Policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1427759670000",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectAcl"
@raphael-riel
raphael-riel / gist:1529604
Created Dec 28, 2011
Slug generator for international text
View gist:1529604
static public function generateSlug($str, $replace = array(), $delimiter = '-'){
if(!empty($replace)){
$str = str_replace((array)$replace, ' ', $str);
}
$clean = self::remove_accents($str);
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
View format_bytes.php
function byteFormat($bytes, $unit = "", $decimals = 2) {
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
$value = 0;
if ($bytes > 0) {
// Generate automatic prefix by bytes
// If wrong prefix given
if (!array_key_exists($unit, $units)) {
$pow = floor(log($bytes)/log(1024));
@raphael-riel
raphael-riel / remove_ws.sh
Created Oct 11, 2011
Remove whitespaces in PHP files in path
View remove_ws.sh
sed -i 's/[ \t]*$//' **/*.php
@raphael-riel
raphael-riel / file_extension_to_mimetype.php
Created Sep 30, 2011
MIME Types by file extension in a PHP array
View file_extension_to_mimetype.php
$types = array(
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'asc' => 'text/plain',
'atom' => 'application/atom+xml',
'atom' => 'application/atom+xml',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
@raphael-riel
raphael-riel / http_response_codes.php
Created Sep 30, 2011
HMTL Reponse code constants in PHP
View http_response_codes.php
//CONSTANTS
define( 'HTTP_CONTINUE', 100 );
define( 'HTTP_SWITCHING_PROTOCOLS', 101 );
define( 'HTTP_PROCESSING', 102 );
define( 'HTTP_OK', 200 );
define( 'HTTP_CREATED', 201 );
define( 'HTTP_ACCEPTED', 202 );
define( 'HTTP_NON_AUTHORITATIVE', 203 );
define( 'HTTP_NO_CONTENT', 204 );
define( 'HTTP_RESET_CONTENT', 205 );
@raphael-riel
raphael-riel / screenshot.sh
Created Sep 29, 2011
Screenshot of X11 Window, every Y seconds.
View screenshot.sh
#!/bin/bash
import -window $(xwininfo -root | grep -Po 'Window id: .*? ' | grep -Po '0x.* ') screenshot.jpg