Skip to content

Instantly share code, notes, and snippets.

View elieandraos's full-sized avatar
🏠
Working from home

Elie Andraos elieandraos

🏠
Working from home
View GitHub Profile
@elieandraos
elieandraos / Creating a prototype function on a dom element
Last active December 4, 2016 15:56
Creating a prototype function on a dom element
$.fn.customFadeIn = function(fn) {
//set opacity to 0 and visibility to visibile
$(this).css({"opacity" : 0, "visibility" : "visible" });
$(this).animate({opacity: 1}, 1000, "swing", function(){
if(typeof fn == 'function')
fn.call(this);
});
};
@elieandraos
elieandraos / Trim a string
Created June 24, 2013 10:50
Trim a string
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
@elieandraos
elieandraos / Default Parametrs Values In Javascript Functions
Created June 24, 2013 10:49
Default Parametrs Values In Javascript Functions
function func(a,b){
if(typeof(a)==='undefined') a = 10;
if(typeof(b)==='undefined') b = 20;
//js code here
}
@elieandraos
elieandraos / Convert Plain to text links to HTML Links
Created June 24, 2013 10:47
Convert Plain to text links to HTML Links
@elieandraos
elieandraos / Get Excel Column Name From Number (index)
Created June 19, 2013 10:19
Get Excel Column Name From Number (index)
function getExcelColumnName($num) {
$numeric = ($num - 1) % 26;
$letter = chr(65 + $numeric);
$num2 = intval(($num - 1) / 26);
if ($num2 > 0) {
return getExcelColumnName($num2) . $letter;
} else {
return $letter;
}
}
@elieandraos
elieandraos / Benchmark a php script
Created June 19, 2013 10:13
Benchmark a php script
<?php
$x = microtime(true);
/* ... Your script goes here ... */
$temp = microtime(true) - $x;
echo "<p> execution time: ".$temp." seconds";
?>
@elieandraos
elieandraos / Sluggify a string with php
Created June 19, 2013 10:09
Sluggify a string with php
/*
* Modifies a string to remove all non ASCII characters and spaces.
* Try slugify("é&asd_æô") for example
*/
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
@elieandraos
elieandraos / Validate Email with php
Created June 19, 2013 10:06
Validate Email with php
/*
* validate email
*/
function is_valid_email($email)
{
if(preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email))
return true;
else
return false;
}
@elieandraos
elieandraos / Symfony Like include_partial functionality
Created June 19, 2013 10:05
Symfony Like include_partial functionality
/* PARTIAL_DIR is a constant that defines the path of the partial file to include */
function get_partial($partialName, $vars = array()){
// start the output buffer
ob_start();
ob_implicit_flush(0);
// extract the variables in the scope of this function
extract($vars);
// include the file
include PARTIAL_DIR.$partialName.'.php';
// clear the output buffer, and return the content
@elieandraos
elieandraos / Remove the index.php from URL (with .htaccess)
Created June 18, 2013 10:38
Remove the index.php from URL (with .htaccess)
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
//For local server (localhost on wamp)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]