Skip to content

Instantly share code, notes, and snippets.

View brunomonteiro3's full-sized avatar

Bruno Monteiro brunomonteiro3

  • Empiricus Research
  • São Paulo, Brazil
View GitHub Profile
@brunomonteiro3
brunomonteiro3 / random-number.js
Created May 10, 2017 01:34
Generate random number between two numbers in JavaScript
function randomIntFromInterval(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
@brunomonteiro3
brunomonteiro3 / php-array-multiple-attributes.php
Created February 27, 2017 18:53
PHP array with multiple attributes
<?php
$items = array();
$items[] = array(
'attr1' => 'value1',
'attr2' => 'value2'
);
foreach ($items as $item) :
echo $item['attr1'];
@brunomonteiro3
brunomonteiro3 / page_status_checker.php
Created February 14, 2017 23:50
PHP - Page status checker. Based on a cURL request, this script will check if an element is rendered on the requested URL and if it's not found, fire an e-mail alert.
<?php
/*
Author: Monteiro, Bruno
E-mail: brunomonteiro3@gmail.com
*/
// Simple cURL settings to retrive all data from the submitted URL
function page_status_checker( $url ) {
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
@brunomonteiro3
brunomonteiro3 / img_p_class_content_filter.php
Created December 7, 2016 23:44
Add class to every image inside a <p> on the_content
<?php
add_filter( 'the_content', 'img_p_class_content_filter', 20);
function img_p_class_content_filter($content) {
$content = preg_replace("/(<p[^>]*)(\>.*)(\<img.*)(<\/p>)/im", "\$1 class='content-img-wrap'\$2\$3\$4", $content);
return $content;
}
@brunomonteiro3
brunomonteiro3 / jquery-script.js
Created November 16, 2016 15:42
jQuery script sample
;(function ($) {
console.log('your-code');
})(jQuery);
@brunomonteiro3
brunomonteiro3 / between.js
Created November 10, 2016 09:09
Check if value is between X or Y
function between(x, min, max) {
return x >= min && x <= max;
}
@brunomonteiro3
brunomonteiro3 / current-date.js
Created November 7, 2016 13:38
Current date in pure JS + jQuery
$(document).ready(function(){
var today = new Date();
var day = today.getDate();
var month = today.getMonth()+1; //January is 0!
var year = today.getFullYear();
if(day < 10) {
day = '0' + day
}
@brunomonteiro3
brunomonteiro3 / query-template.php
Created September 26, 2016 18:23
Query posts with specific template
<?php
/*
Template Name: List
*/
?>
<style>
td, tr{
border: 1px solid grey;
padding: 10px;
@brunomonteiro3
brunomonteiro3 / transition.less
Created September 19, 2016 16:53
MIXIN - LESS - Transitions
.transition (@transition) {
-webkit-transition: @transition;
-moz-transition: @transition;
-ms-transition: @transition;
-o-transition: @transition;
}
@brunomonteiro3
brunomonteiro3 / gist:b28d958471be9cc577236f1564014649
Created September 3, 2016 14:58
jQuery - Do something after X pixels.
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
...
} else {
...
}
});