Skip to content

Instantly share code, notes, and snippets.

View pelusium's full-sized avatar

Mauro Gama pelusium

View GitHub Profile
@pelusium
pelusium / parse-xml.php
Created February 1, 2018 21:48 — forked from stojg/parse-xml.php
Parsing a huge XML with closure in PHP
<?php
// Open the XML
$handle = fopen('file.xml', 'r');
// Get the nodestring incrementally from the xml file by defining a callback
// In this case using a anon function.
nodeStringFromXMLFile($handle, '<item>', '</item>', function($nodeText){
// Transform the XMLString into an array and
print_r(getArrayFromXMLString($nodeText));
@pelusium
pelusium / isOver16.js
Created January 11, 2017 14:58
Jquery validator over 16 years
jQuery.validator.addMethod('isOver16', function(value, element) {
var birthDate = value.split('-');
var tempDate = new Date((parseInt(birthDate[2])+16), parseInt(birthDate[1]-1), parseInt(birthDate[0]));
return (tempDate <= new Date());
});
@pelusium
pelusium / isValidName.js
Created January 11, 2017 14:57
Validate Name PT
jQuery.validator.addMethod('isValidName', function(value, element) {
var regex = /(^([ A-Za-zá-úÁ-Ú.\s]){1,200})+$/;
var names = rtrim(value).split(' ');
var test = true;
if( names.length <= 1 ){
test = false;
}else{
for( var k=0; k< names.length; ++k ){
if( !regex.test( names[k] ) ){
test = false;
@pelusium
pelusium / isValidPhoneNumber.js
Last active January 11, 2017 14:55
Regex telefone PT
jQuery.validator.addMethod('isValidPhoneNumber', function(value, element) {
var regex = new RegExp('^[0-9]{9}$');
var isValid = true;
if(value.charAt(0) != 2 && value.charAt(0) != 3 && value.charAt(0) != 9 ) isValid = false;
if( (value.charAt(0) == 9) && (value.charAt(1) != 6 && value.charAt(1) != 1 && value.charAt(1) != 3 && value.charAt(1) != 2 && value.charAt(1) != 4)) isValid = false;
if (value.charAt(0) == 3 && value.charAt(1) == 5 && value.charAt(2) == 1) isValid = false;
if(formValidation_isInvalidPhoneNumbers(value)) isValid = false;
return this.optional(element) || (regex.test(value) && isValid)
});
function formValidation_isInvalidPhoneNumbers( phone ){
@pelusium
pelusium / WriteToSlack
Last active August 29, 2015 14:15
L4 - Write to Slack
<?php
class WriteToSlack {
public function write($params){
$type = $params['type'];
if($type == "error")
@pelusium
pelusium / .gitignore
Created June 18, 2014 09:35
gitignore
### Laravel ###
_ide_helper.php
/bootstrap/compiled.php
/vendor
.env.local.php
.env.php
composer.phar
composer.lock
@pelusium
pelusium / path_info
Created March 12, 2014 15:25
Laravel - Path Folder
**
* Path to the 'app' folder
*/
echo app_path();
/**
* Path to the project's root folder
*/
echo base_path();
/**
* Path to the 'public' folder
@pelusium
pelusium / content.ini.append.php
Created September 30, 2013 16:05
vimeo custom tag
AvailableCustomTags[]=vimeo
IsInline[vimeo]=true
[vimeo]
CustomAttributes[]=width
CustomAttributes[]=height
CustomAttributes[]=link
CustomAttributesDefaults[width]=610
CustomAttributesDefaults[height]=400
CustomAttributesDefaults[link]=
@pelusium
pelusium / me-no-mundo-europa.tpl
Created September 13, 2013 09:43
- Filter by class - get children/parent/grandparent
{def $areas_negocio_list = fetch( 'content', 'list',
hash( 'parent_node_id', $areas_negocio_id.node_id, 'class_filter_type', 'include',
'class_filter_array', array( 'folder' ),
'depth', 3 ) )}
{def $dep = 0}
{def $number_children = 0}
{foreach $areas_negocio_list as $area_negocio}
@pelusium
pelusium / facebook-sdk.tpl
Created August 29, 2013 10:50
Obter a lingua actual do sistema
{def $locale = ezini( 'RegionalSettings', 'Locale', 'site.ini' )}