Skip to content

Instantly share code, notes, and snippets.

View tarciozemel's full-sized avatar

Tárcio Zemel tarciozemel

View GitHub Profile
@tarciozemel
tarciozemel / gist:1884583
Last active June 22, 2016 16:52 — forked from adrienjoly/include.js
JavaScript: incluir arquivos js/css dinamicamente
/*
* Ex:
* include("http://mysite.com/bookmarklet.css");
* include("http://mysite.com/bookmarklet.js");
*/
let include = ( src, callback ) => {
let ext = src.split( /[\#\?]/ )[ 0 ].split( '.' ).pop().toLowerCase();
let inc;
if ( ext === 'css' ) {
@tarciozemel
tarciozemel / .gitignore
Last active May 25, 2022 13:03
Git: .gitignore
### User template
# Folders
bower_components/
.project
.nuxt
# Compiled source
*.class
*.com
*.dll
@tarciozemel
tarciozemel / gist:4420514
Created December 31, 2012 15:09
JavaScript: Media Queries sob demanda
/**
* Carregamento condicional de css/img conforme a resolução.
*
* Através de data-*, permite que somente as folhas de estilos (e,
* opcionalmente, imagens) que batem com determinada resolução sejam
* carregados e entrem em ação.
*
* Deve-se usar seguindo o modelo:
* <link rel="stylesheet"
* class="mediaquerydependent"
@tarciozemel
tarciozemel / gist:4511190
Created January 11, 2013 14:46
WordPress: busca com Custom Fields
//
// By default, WordPress comes with a handy search but it only search in post
// titles and contents. If you are working on a custom post type, you most
// probably using custom fields to store its attributes. For example, A
// Property custom post type would have address, city and state custom fields.
// You may have used WP_Query object with meta_query setup, But, it does not
// work. If you do not use “s” attribute, it will overwrite the default search
// and If you use it, it will not return the expected results. This snippet will
// use posts_clauses filter to inject the meta query that will combine with the
// WordPress’s default search parameter.
@tarciozemel
tarciozemel / gist:6452825
Last active December 22, 2015 09:38
htaccess: modo de manutenção
# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^123.456.789.000 # whatismyip.com
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=302,L]
</IfModule>
@tarciozemel
tarciozemel / gist:6978074
Created October 14, 2013 16:08
Git: criar repo no GitHub
Create a new repository on the command line
-------------------------------------------
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [SSH GIT ADDRESS]
git push -u origin master
@tarciozemel
tarciozemel / gist:7310567
Created November 4, 2013 22:46
PHP: email encode
function emailEncode($e)
{
$email_len = strlen($e);
for ($i = 0; $i < $email_len; $i++) {
$output .= '&#'.ord($e[$i]).';';
}
return $output;
}
@tarciozemel
tarciozemel / gist:0bf35374a64fe6c9e2d1
Created April 20, 2015 17:11
JavaScript: lightweight selector implementation
//
// Returns first element that matches CSS selector {expr}.
// Querying can optionally be restricted to {container}’s descendants
//
function $( expr, container ) {
return typeof expr === 'string' ? ( container || document ).querySelector( expr ) : expr || null;
}
//
@tarciozemel
tarciozemel / slugify.js
Created January 22, 2018 17:17 — forked from eek/slugify.js
Vanilla JavaScript Slugify + Accent removal - Just another JavaScript Slugifier with an extra line for Accent Removal
function slugify(text) {
return text.toString().toLowerCase().trim()
.normalize('NFD') // separate accent from letter
.replace(/[\u0300-\u036f]/g, '') // remove all separated accents
.replace(/\s+/g, '-') // replace spaces with -
.replace(/&/g, '-and-') // replace & with 'and'
.replace(/[^\w\-]+/g, '') // remove all non-word chars
.replace(/\-\-+/g, '-') // replace multiple '-' with single '-'
}
/* Headers out of order (i.e. h2 before h1 etc.)
Result: dotted blue outline
@see https://twitter.com/Una/status/1277652897606635523
*/
h2 ~ h1,
h3 ~ h1,
h4 ~ h1,
h5 ~ h1,
h6 ~ h1,
h3 ~ h2,