Skip to content

Instantly share code, notes, and snippets.

View pawiromitchel's full-sized avatar
🔥
By doing nothing, you become nothing

Mitchel pawiromitchel

🔥
By doing nothing, you become nothing
View GitHub Profile
@pawiromitchel
pawiromitchel / .htaccess
Last active January 27, 2017 11:28
htaccess - To remove the .php in the url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
@pawiromitchel
pawiromitchel / slugify.php
Last active January 27, 2017 11:19
PHP - replacing special characters like à->a, è->e
<?php
function slugify($text,$strict = false) {
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d.]+~u', '-', $text);
// trim
$text = trim($text, '-');
setlocale(LC_CTYPE, 'en_GB.utf8');
@pawiromitchel
pawiromitchel / smart_resize_image.php
Created January 27, 2017 11:21
PHP - easy image resize function
<?php
/**
* easy image resize function
* @param $file - file name to resize
* @param $string - The image data, as a string
* @param $width - new image width
* @param $height - new image height
* @param $proportional - keep image proportional, default is no
* @param $output - name of the new file (include path if needed)
* @param $delete_original - if true the original image will be deleted
@pawiromitchel
pawiromitchel / array_utf8_encode.php
Created January 27, 2017 11:22
PHP - transorm array strings to UTF-8
<?php
function array_utf8_encode($dat)
{
if (is_string($dat))
return utf8_encode($dat);
if (!is_array($dat))
return $dat;
$ret = array();
foreach ($dat as $i => $d)
@pawiromitchel
pawiromitchel / ceiling.php
Created January 27, 2017 11:23
PHP - MS Exel ceiling function
<?php
function ceiling($number, $significance = 1)
{
return ( is_numeric($number) && is_numeric($significance) ) ? (ceil($number/$significance)*$significance) : false;
}
@pawiromitchel
pawiromitchel / watermark_image.php
Created January 27, 2017 11:23
PHP - watermarking images
<?php
function watermark_image($target, $wtrmrk_file, $newcopy)
{
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng($wtrmrk_file);
$im = imagecreatefromjpeg($target);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
@pawiromitchel
pawiromitchel / daysBetween.js
Created January 27, 2017 11:24
JS - Calculate the difference between 2 dates
function daysBetween(one, another) {
return Math.round(Math.abs(one - another) / 8.64e7);
}
// usage
a = daysBetween(new Date(date1), new Date(date2))
@pawiromitchel
pawiromitchel / getUriParam.js
Created January 27, 2017 11:25
JS - get the parameter from the URI
function getUriParam(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
// usage -> url: http://localhost/index.html?id=1
var a = getUriParam('id');
@pawiromitchel
pawiromitchel / removeDuplicates.js
Created January 27, 2017 11:26
JS - remove duplicates from an array
function removeDuplicates(originalArray, prop) {
var newArray = [];
var lookupObject = {};
for(var i in originalArray) {
lookupObject[originalArray[i][prop]] = originalArray[i];
}
for(i in lookupObject) {
newArray.push(lookupObject[i]);
@pawiromitchel
pawiromitchel / search.js
Created January 27, 2017 11:27
JS - search within a table
$(document).ready(function(){
$("#search").keyup(function () {
var value = this.value.toLowerCase().trim();
$("table tr").each(function (index) {
if (!index) return;
$(this).find("td").each(function () {
var id = $(this).text().toLowerCase().trim();
var not_found = (id.indexOf(value) == -1);
$(this).closest('tr').toggle(!not_found);