Skip to content

Instantly share code, notes, and snippets.

View marcelo-ribeiro's full-sized avatar

Marcelo Ribeiro marcelo-ribeiro

  • Front-End Developer
  • Salvador, Bahia, Brasil
View GitHub Profile
function remove_http($url) {
$disallowed = array('http://', 'https://');
foreach($disallowed as $d) {
if(strpos($url, $d) === 0) {
return str_replace($d, '', $url);
}
}
return $url;
}
@marcelo-ribeiro
marcelo-ribeiro / back-to-top.js
Last active August 10, 2016 19:55
Smooth Scroll to top and to target
// ---------------------------------------------------------
// Back to Top
// ---------------------------------------------------------
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('#back-top').fadeIn();
} else {
$('#back-top').fadeOut();
}
});
<section class="section">
<header class="section--header">
<div class="container">
<h1 class="section--title">Section Title</h1>
</div>
</header>
<main class="section--content">
<div class="container">
<!-- ... -->
</div>
@marcelo-ribeiro
marcelo-ribeiro / angular-jsonp.js
Last active August 28, 2017 18:16
Angular JSONP
$http({
method: 'JSONP',
url: $sce.trustAsResourceUrl(url),
jsonpCallbackParam: 'callback'
})
.then(function(response) {
console.log(response);
});
@marcelo-ribeiro
marcelo-ribeiro / edit_image.js
Last active September 12, 2017 04:38
WP REST API Upload Image
var settings = {
"async": true,
"crossDomain": true,
"url": "http://www.marcelo-ribeiro.tk/wp-json/wp/v2/media/48",
"method": "POST",
"headers": {
"authorization": "Basic bWFyY2Vsb3JpYmVpcm86QDg1ODM1OTU0Iw==",
"content-type": "application/json"
},
"processData": false,
@marcelo-ribeiro
marcelo-ribeiro / allow-cors-origin.php
Last active October 10, 2017 22:03
WP REST API - SNIPPETS
// Access-Control-Allow-Origin
add_action( 'rest_api_init', function() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', function( $value ) {
$origin = get_http_origin();
if ( $origin && in_array( $origin, array(
'http://localhost'
) ) ) {
header( 'Access-Control-Allow-Origin: ' . esc_url_raw( $origin ) );
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
@marcelo-ribeiro
marcelo-ribeiro / categories-list.php
Created October 20, 2017 21:50
List categories and subcategories in JSON format
$args = [
'taxonomy' => 'category',
'hide_empty' => 0,
'parent' => 0
];
function _get_child_terms( $items ) {
foreach ( $items as $item ) {
$item->children = get_terms( 'category', array( 'child_of' => $item->term_id, 'hide_empty' => 0 ) );
if ( $item->children ) _get_child_terms( $item->children );
@marcelo-ribeiro
marcelo-ribeiro / defaults-overrides.js
Last active March 2, 2018 15:28
ES6 defaults / overrides pattern
var defaults = {
bar: 'no',
baz: 'works!'
};
function foo( options ) {
Object.assign( defaults, options );
console.log( defaults );
}
@marcelo-ribeiro
marcelo-ribeiro / _variables-ease.scss
Created March 15, 2018 20:39
Material Design Ease Timing Functions Variables
// TIMING FUNCTIONS
$ease: cubic-bezier(0.4, 0, 0.2, 1);
$ease-in: cubic-bezier(0.4, 0.0, 1, 1);
$ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);
$ease-in-out: cubic-bezier(0.4, 0.0, 0.6, 1);
@marcelo-ribeiro
marcelo-ribeiro / ajax-pagination.js
Last active March 20, 2018 17:38
Wordpress - Ajax Pagination
$(function() {
var paged = 1,
isLoading = false,
posts = $('.posts'),
button = $('.read_more'),
foundPosts = button.attr('data-found-posts');
(function() {
hasMoreItens() && button.fadeIn();