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
@marcelo-ribeiro
marcelo-ribeiro / gh-pages-deploy.md
Created June 26, 2019 20:53 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@marcelo-ribeiro
marcelo-ribeiro / vscode-format-settings.json
Last active January 8, 2020 18:11
VSCode Format Settings
{
"workbench.list.openMode": "doubleClick",
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Material Theme Palenight High Contrast",
"editor.fontFamily": "Dank Mono, Cascadia Code, Fira Code",
"editor.fontSize": 13,
"editor.lineHeight": 26,
"editor.fontLigatures": true,
"editor.tabSize": 2,
"editor.fontWeight": "400",
@marcelo-ribeiro
marcelo-ribeiro / example-extend-defaults.js
Last active October 18, 2018 18:21
Polyfill js to extend objects and child objects
var defaults = {
firstName = 'John',
lastName = 'Doe'
};
var options = {
firstName = 'Jane'
};
extendDefaults(defaults, options);
@marcelo-ribeiro
marcelo-ribeiro / trim-all.js
Last active September 3, 2018 17:00
Trim All White Spaces
(function () {
if (!String.prototype.trimAll) {
String.prototype.trimAll = function () {
return this.replace(/\s+/g, '');
};
}
})();
// Example
console.log(' Hello World '.trimAll());
@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 / loadMyAjax.js
Last active June 19, 2018 19:40
Javascript Ajax Cross-browser - Method POST
var postsList = document.querySelector('.posts_list');
var paged = 1;
var countPosts = postsList.dataset.countPosts;
var postsPerPage = parseInt(postsList.dataset.postsPerPage);
window.addEventListener( 'onInfinite', getPosts );
function hasMoreItens() {
return postsList.children.length < countPosts;
}
@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 / 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 / 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 / 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,