Skip to content

Instantly share code, notes, and snippets.

David CHC davidchc

Block or report user

Report or block davidchc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
davidchc / Template.php
Created Sep 12, 2019
Criar uma classe de template
View Template.php
class Template
private $data = [];
private $path;
public function __construct($path='')
$this->path = $path;
View date_range.php
function getRangeDate($start, $end, $increment = '+1 days') {
$current = strtotime($start);
$end = strtotime($end);
$results = [];
while($current < $end){
$results[] = date('Y-m-d', $current);
$current = strtotime($increment, strtotime(date('Y-m-d', $current)));
davidchc / .htaccess
Created Aug 8, 2019
Habilitando Gzip Deflate
View .htaccess
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
davidchc / the_breadcrumb.php
Created Jun 10, 2019
Função para Criar Breadcrumb no WordPress
View the_breadcrumb.php
function the_breadcrumb($sep = ' > ') {
if (!is_front_page()) {
echo '<div class="breadcrumbs">';
echo '<a href="'.get_option('home').'">'.get_bloginfo('name').'</a>';
davidchc / functions.php
Created Mar 22, 2019
Exemplo de criação de shortcode com código existente
View functions.php
add_shortcode("star_rating", "fn_star_ratings");
function fn_star_ratings($atts, $content=null){
$data = shortcode_atts(["id" => 0], $atts);
return kk_star_ratings($data["id"]);
add_shortcode("star_rating_get", "fn_star_rating_get");
davidchc / home.html
Created Jan 9, 2019
Exemplo de adicionar carregamento ajax, diretamente pelo manipulador do elemento na tag. Essa abordagem não é interessante pq vc precisa de muitos pontos de alteração, e com isso podendo correr erros.
View home.html
<h1>Página Home</h1>
davidchc / drawmenu.php
Created Jan 2, 2019
Exemplo de fazer um menu com submenu
View drawmenu.php
$pdo = new PDO("mysql:host=localhost;dbname=example", "root", "");
$sql = "SELECT * FROM categories ORDER BY parent, id ASC";
$stmt = $pdo->prepare($sql);
$rows = $stmt->fetchAll();
$results = [];
foreach($row as $row) {
View ip.php
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
View index.php
$redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location: $redirect");
davidchc / exemplo-sleep.js
Created Oct 30, 2018
Exemplo de Sleep com JavaScript
View exemplo-sleep.js
let data = [1,2,3,4,5,6,7,8,9,10];
let factor = 2;
const sleep = async (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
const start = async (data) => {
let total = data.length;
You can’t perform that action at this time.