Skip to content

Instantly share code, notes, and snippets.

View alexdumont's full-sized avatar

Alexandre Dumont alexdumont

View GitHub Profile
@alexdumont
alexdumont / gist:1df846047cfdead33b2b
Created October 16, 2015 08:14
URL and Javascript
window.location.host //www.test.com:8082
window.location.hostname // www.test.com
window.location.port // 8082
window.location.protocol // http
window.location.pathname // index.php
window.location.href // http://www.test.com:8082/index.php#tab2
window.location.hash // #tab2
window.location.search // ?foo=123
$(location).attr('host'); // www.test.com:8082
@alexdumont
alexdumont / Slug
Created May 12, 2015 08:08
Function which create a slug from string
<?php
function slug($str, $delimiter='-', $charset='utf-8') {
$str = preg_replace("`\[.*\]`U","",$str);
$str = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$str);
$str = htmlentities($str, ENT_NOQUOTES, $charset);
$str = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig);`i","\\1", $str );
$str = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $str);
$str = ( $str == "" ) ? $type : strtolower(trim($str, '-'));
$str = strtolower($str);
@alexdumont
alexdumont / gist:5c5ee873a0de7375f221
Last active August 29, 2015 14:20
A simple code for a form login by firewall in FOSUserBundle (Symfony2). One concept : overwriting.
<?php
namespace Pr3ss\UserBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use FOS\UserBundle\Controller\SecurityController as BaseController;
afghanistan : Afghanistan
albania : Albania
algeria : Algeria
american_samoa : American Samoa
andorra : Andorra
angola : Angola
anguilla : Anguilla
antigua_and_barbuda : Antigua and Barbuda
argentina : Argentina
armenia : Armenia
function Remplace(a,b, expr) {
var i=0
while (i!=-1) {
i=expr.indexOf(a,i);
if (i>=0) {
expr=expr.substring(0,i)+b+expr.substring(i+a.length);
i+=b.length;
}
}
return expr
@alexdumont
alexdumont / css reset properties
Created October 31, 2014 07:56
css reset properties
animation : none;
animation-delay : 0;
animation-direction : normal;
animation-duration : 0;
animation-fill-mode : none;
animation-iteration-count : 1;
animation-name : none;
animation-play-state : running;
animation-timing-function : ease;
backface-visibility : visible;
@alexdumont
alexdumont / no-direct-download
Last active August 29, 2015 14:08
No direct download with a HTACCESS
RewriteEngine On
RewriteBase /
# allow these referers to passthrough
RewriteCond %{HTTP_REFERER} ^http(s)?://(www\.)?cub3\.be
RewriteRule ^ - [L]
<FilesMatch "\.(mov|mp3|jpg|pdf|doc|docx|xls|xlsx)$">
ForceType application/octet-stream
Header set Content-Disposition attachment