Skip to content

Instantly share code, notes, and snippets.

@solepixel
solepixel / .htaccess
Created Aug 29, 2015
Hash signs in URI
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} /([^?\ ]+)
RewriteRule (.*) index.php/%1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
@solepixel
solepixel / Session.php
Created Aug 29, 2015
CodeIgniter function with @ symbol
View Session.php
<?php
// Lines 706-721 of system/libraries/Session.php
function _unserialize($data)
{
$data = @unserialize(strip_slashes($data));
if (is_array($data))
{
foreach ($data as $key => $val)
{
@solepixel
solepixel / remap.php
Created Aug 29, 2015
CodeIgniter _remap function.
View remap.php
<?php
function _remap($method)
{
if (method_exists($this, $method)){
$this->$method($this->uri->segment(3));
} else {
$this->index($method);
}
}
@solepixel
solepixel / ajax-json.js
Created Aug 29, 2015
jQuery + JSON + AJAX (old blog post)
View ajax-json.js
function ajaxJSON(json){
if(json){
var obj = (typeof(json) == 'object') ? json : eval('(' + json + ')');
eval(obj.script);
if(obj.confirm){
obj.success = confirm(obj.confirm);
}
return obj;
}
return {};
@solepixel
solepixel / insert-example.php
Created Aug 29, 2015
PHP MySQL Class (old blog post)
View insert-example.php
<?php
$data = array(
'name' => $_POST['name'],
'email' => $_POST['email'],
'comment' => $_POST['comment']
);
$add_comment = new mySQL();
$new_comment_id = $add_comment->insert('comments', $data);
@solepixel
solepixel / create-thumb.php
Created Aug 29, 2015
Image thumbnail creator
View create-thumb.php
<?php
/*
JPEG / GIF / PNG Resizer / Image Viewer
Parameters (passed via URL):
src = path / url of jpeg or png image file
percent = if this is defined, image is resized by it's
value in percent (i.e. 50 to divide by 50 percent)
w = image width
h = image height
@solepixel
solepixel / force-download.php
Created Aug 29, 2015
Force Download Snippet
View force-download.php
<?php
$filename = $my_file_name;
if(substr($filename,0,1) != "/"){
$filename = "/". $filename;
}
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
$file_extension = strtolower(substr(strrchr($filename,"."),1));
@solepixel
solepixel / valid-email.php
Created Aug 29, 2015
Validate Email address (old blog post)
View valid-email.php
<?php
function validEmail($email_address){
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email_address)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email_address);
$local_array = explode(".", $email_array[0]);
@solepixel
solepixel / custom-sort.sql
Created Aug 29, 2015
Custom Sort Order in MySQL (order by case)
View custom-sort.sql
ORDER BY CASE
WHEN `col` = ‘item’ THEN 1
WHEN `col` = ‘thing’ THEN 2
WHEN `col` = ‘stuff’ THEN 3
WHEN `col` = ‘boom’ THEN 4
ELSE 5
END
@solepixel
solepixel / sample.css
Created Aug 29, 2015
Sample CSS code (old blog post)
View sample.css
margin-bottom: 12px;
font: normal 1.1em "Lucida Sans Unicode", serif;
background: url(img/quote.gif) no-repeat;
padding-left: 28px;
color: #555;