Skip to content

Instantly share code, notes, and snippets.

View maxparm's full-sized avatar

Maxime Parmentier maxparm

View GitHub Profile
@maxparm
maxparm / jquery-input-number-filter.js
Created March 26, 2012 23:47
JS - jQuery Allow only numeric characters in HTML input
$(function(){
$('input[name="number"]').bind('keypress', function(e){
var keyCode = (e.which)?e.which:event.keyCode
return !(keyCode>31 && (keyCode<48 || keyCode>57));
});
});
@maxparm
maxparm / jquery-input-radio-val.js
Created March 26, 2012 22:54
JS - jQuery get checked value from input radio
$(function(){
$('input[name="myInput"]:checked').val();
});
@maxparm
maxparm / gist:2029829
Created March 13, 2012 16:41
JS - Jquery detect keypress enter
$('#element').on('keypress', function(e) {
if(e.which == 13) {
// action();
e.preventDefault();
}
});
@maxparm
maxparm / FooController.php
Created March 12, 2012 18:54
Lithium - redirect in controller's _init
class FooController extends \lithium\action\Controller {
public function _init() {
parent::_init();
$userNotConnected = true;
if($userNotConnected) {
return $this->redirect('logout', array('exit'=>true));
}
}
@maxparm
maxparm / test.php
Created September 27, 2011 21:46
PHP - isset, empty which one?
<?php
/**
* Test if a variable is set and not empty
*/
//var not defined
var_dump(isset($var) && !empty($var)); // return false
var_dump(!empty($var)); // return false
var_dump($var); // throw a warning
var_dump(!$var); // throw a warning
@maxparm
maxparm / test.js
Created July 27, 2011 23:12
JS - Short Hand default value to variable
var foo;
var bar = foo || 'Hello World!';
console.log(bar); //return 'Hello World'
@maxparm
maxparm / test.js
Created July 26, 2011 22:14
JS - Boolean values in javascript conditions
// Boolean Value
console.log('===== Boolean Value!');
console.log( ( 1 ) ? 'true' : 'false' ); // true
console.log( ( '0' ) ? 'true' : 'false' ); // true
console.log( ( '1' ) ? 'true' : 'false' ); // true
console.log( ( [] ) ? 'true' : 'false' ); // true
console.log( ( {} ) ? 'true' : 'false' ); // true
console.log( ( '' ) ? 'true' : 'false' ); // false
console.log( ( 0 ) ? 'true' : 'false' ); // false
console.log( ( NaN ) ? 'true' : 'false' ); // false
@maxparm
maxparm / IndexController.php
Created June 17, 2011 20:12
Index Controller
<?php
namespace admin\controllers;
class IndexController extends \lithium\action\Controller {
public function index() {
}
}
?>
@maxparm
maxparm / libraries.php
Created June 17, 2011 19:03
LITHIUM - bootstrap libraries
<?php
//...
/**
* Add the Lithium core library. This sets default paths and initializes the autoloader. You
* generally should not need to override any settings.
*/
Libraries::add('lithium');
@maxparm
maxparm / UserController.php
Created June 15, 2011 23:21
LITHIUM - User logout
<?php
namespace app\controllers;
use app\models\Users;
use lithium\security\Auth;
use lithium\storage\Session;
class UserController extends \lithium\action\Controller {
//actions ....