Skip to content

Instantly share code, notes, and snippets.

View FernandoBasso's full-sized avatar

Fernando Basso FernandoBasso

View GitHub Profile
@FernandoBasso
FernandoBasso / quotes-of-wisdom.txt
Last active October 22, 2020 12:28
Quotes of Wisdom
“I fear not the man who has practiced 10,000 kicks once, but I fear the
man who has practiced one kick 10,000 times.”
— Bruce Lee
“Eu não temo o homem que pratiou 10.000 chutes uma vez, mas sim do
homem que praticou um chute 10.000 vezes.”
“Se quiser testar o caráter de uma pessoa, dê poder a ela.”
— Abraham Lincoln
@FernandoBasso
FernandoBasso / pdotransaction.php
Created May 19, 2016 19:10
Example of PDO transaction with insertion in two tables and a loop on the second one.
<?php
public function salvaPedidoDb() {
try {
$this->db->beginTransaction();
$sql1 = 'INSERT INTO pedidos (pessoa_fk, preco_total) VALUES (:pessoa_fk, :preco_total)';
$sth1 = $this->db->prepare($sql1);
<?php
class Person {
private $name;
public function __construct($name = '') {
$this->name = $name;
}

He who knows not and knows not he knows not, He is a fool - Shun him.

He who knows not and knows he knows not, He is simple - Teach him.

He who knows and knows not he knows, he is asleep - Awaken him.

He who knows and knows that he knows, He is wise - Follow him.

@FernandoBasso
FernandoBasso / urlize.php
Last active April 15, 2021 10:19
Urlize a string for pretty urls and SEO.
<?php
// Thanks to: http://cubiq.org/the-perfect-php-clean-url-generator
function toAscii( $str, $replace = array(), $delimiter = '-' ) {
if( ! empty( $replace ) ) {
$str = str_replace( ( array ) $replace, ' ', $str);
}
$clean = iconv( 'UTF-8', 'ASCII//TRANSLIT', $str );
$clean = preg_replace( "/[^a-zA-Z0-9\/_|+ -]/", '', $clean );
@FernandoBasso
FernandoBasso / sed-reverse-lines.txt
Created March 14, 2016 23:43
Trying to understand how "reverse lines" in sed works
file:
AA
BB
CC
DD
sed command:
@FernandoBasso
FernandoBasso / function-exression-ES5-vs-ES6.js
Created January 25, 2016 12:25
Using () to force a IIFE in ES5 functions vs in ES6 arrow functions
var l = console.log.bind(console);
// ↓
var jedi1 = ((name, skill) => ({
name: name,
skill: skill
}))('Master Yoda', 'The Force') ;
//↑ ↑ Can't close ) at the end.
l(jedi1.name);
l(jedi1.skill);
failed_dbs='failed-databases.txt';
errors_file='errors-backup.txt';
dirdate=$(date +'%Y-%m-%d');
# site host user pass dbname
hosts=(
'projeto1 foo.bar.net prjeto1user 1234 projeto1dbname'
'projeto2 foo.bar.net prjeto2user 1234 projeto2dbname'
'projeto3 foo.bar.net prjeto3user 1234 projeto3dbname'
@FernandoBasso
FernandoBasso / three-table-join.sql
Created August 14, 2015 13:54
Three-table sql join
-- I have the tables `category`, `subscription` and `document`. Document
-- references subscription, and subscription references category. I am trying to
-- get the category name based on a documents PK. I am doing something like this:
SELECT category_name FROM categorias
INNER JOIN subscription ON category_fk = category_pk
INNER JOIN documents ON subscription_fk = document_pk
AND document_pk = 14;
<%= form_for @user_category do |f| %>
<p>
<%= f.label :description %>
<%= f.text_field :description %>
</p>
<p>
<%= f.radio_button :status, true, :id => 'status_true' %>
<%= f.label 'Ativo', :for => 'status_true' %>