Skip to content

Instantly share code, notes, and snippets.

View badah's full-sized avatar

Daniel Hernandes badah

View GitHub Profile
@badah
badah / import-csv-data-into-table.sql
Last active March 28, 2019 20:43
MYSQL: import csv data into table
# Create table with same csv headers.
CREATE TABLE table_name ( id mediumint(9) NOT NULL, {..}, PRIMARY KEY (id) );
# Load csv into table.
LOAD DATA INFILE '{abspath}/my-data.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
@badah
badah / export-mysql-to-csv.sh
Created March 26, 2019 22:01
MYSQL: Export to .csv file
mysql -u{user} -p{pass} -h{host} {database} -e "{sql}" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > /{path}/my-export-{time}.csv
@badah
badah / agressive-hook.php
Last active April 26, 2017 21:05
Wordpress: Agressively remove elements from page
class Admin {
public function remove_profile_page_options( $subject ) {
$subject = preg_replace( '#<h2>Opções pessoais</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>Nome</h2>#s', '', $subject, 1 );
$subject = preg_replace( '#<h2>Sobre o usuário</h2>.+?/table>#s', '', $subject, 1 );
$subject = preg_replace( '#<div class="yoast yoast-settings">.+?/div>#s', '', $subject, 1 );
$subject = preg_replace( '#<tr class="user-url-wrap">.+?/tr>#s', '', $subject, 1 );
$subject = preg_replace( '#<tr class="user-googleplus-wrap">.+?/tr>#s', '', $subject, 1 );
$subject = preg_replace( '#<tr class="user-twitter-wrap">.+?/tr>#s', '', $subject, 1 );
@badah
badah / remove_string_mask.php
Created February 22, 2017 21:21
Remove string mask
<?php
$masked_input = '30.029.920-19';
preg_replace('/[^0-9]/', '', $masked_input);
@badah
badah / git -package-release.txt
Created February 7, 2017 21:22
Git: make a zip package with modified files in release branch
git archive -o <repo.zip> HEAD $(git diff --name-only <release-branch> master)
@badah
badah / Demo_Mascara_Telefone.html
Created May 30, 2016 16:58 — forked from VictorHugoBatista/Demo_Mascara_Telefone.html
Demo de máscara com expressão regular de telefone brasileiro que aceita número de 8 e 9 dígitos com DDD nos formatos (11) 2222-3333 e (11) 92222-3333. Fonte: http://elcio.com.br/ajax/mascara/
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Demo Máscara Telefone</title>
</head>
<body>
Telefone: <input onkeypress="mascaraTelefone(this)"/><br />
<script>
/*
@badah
badah / titlecase.php
Created March 16, 2016 23:29
PHP - convert any sentence (pt-br) in Title format
<?php
function title_case($string, $delimiters = array(" ", "-", ".", "'", "O'", "Mc"),
$exceptions = array(
"de", "da", "dos", "das", "do", "I", "e","II", "III", "IV",
"V", "VI", "MBA", "AADM", "em", "in", "and", "or", "of", "EMBA"
)){
$string = mb_convert_case($string, MB_CASE_TITLE, "UTF-8");
foreach ($delimiters as $dlnr => $delimiter) {
$words = explode($delimiter, $string);
@badah
badah / wpallimport-fillparentterm.php
Last active April 7, 2016 18:51
WP - wpallimport[plugin], fill parent term in taxonomy
<?php
/*
* WpAllImport - Fill parent term in taxonomy
* Ex:
* 1 - [match_pattern({grauacadmico[1]}, array("string1","string2"), "Parent Term")]
* 2 - [match_pattern({grauacadmico[1]}, array("string1","string2"))]
*
*/
function match_pattern($my_field, $my_array, $parent = null) {
$result = "";
@badah
badah / responsive-embed-video.html
Created October 13, 2015 01:02
CSS: Responsive embed video trick
<style type="text/css">
.video-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px; height: 0; overflow: hidden;
}
.video-container iframe,
.video-container object,
.video-container embed {