Skip to content

Instantly share code, notes, and snippets.

View calexandrepcjr's full-sized avatar
🎯
Focusing

Carlos Alexandre calexandrepcjr

🎯
Focusing
View GitHub Profile
@calexandrepcjr
calexandrepcjr / list_charset_and_collations_to_mysql.sql
Last active September 9, 2019 14:27
This routine helps when someone needs to review the entire database charset/collation at once. You can run this SP and store in a CSV to help analysis or just manipulate the result inside the DB.
/*
TO MYSQL
List your entire schema + tables + columns charset and collations to overall review
WHAT IT DOES:
- The stored procedure goes into MySQL's information_schema table
and retrieves the overall info about your database;
HOW TO USE:
@calexandrepcjr
calexandrepcjr / charset_collation_conversion.sql
Last active September 9, 2019 11:51
MySQL UTF-8 charset does not handle all Unicode characters, being entirely anormal to the own UTF-8 concept. The solution is convert to utf8mb4, the MySQL charset that proper implements UTF-8 charset range, acception all Unicode characters
/*
https://stackoverflow.com/questions/37364618/utf8mb4-unicode-ci-vs-utf8mb4-bin
https://drupal.stackexchange.com/questions/166405/why-are-we-using-utf8mb4-general-ci-and-not-utf8mb4-unicode-ci/184528#184528?newreg=82d15487d4b84bbe978ce38e687baaa9
https://pentahointegra.blogspot.com/2015/09/utf8generalci-vs-utf8unicodeci-what.html
Note: in new versions of MySQL use utf8mb4, rather than utf8, which is the same
UTF-8 data format with same performance but previously only accepted the first
65,536 Unicode characters.
Accuracy
@calexandrepcjr
calexandrepcjr / .htaccess
Created July 19, 2019 18:16 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@calexandrepcjr
calexandrepcjr / has_daily_limit_laravel_trait.php
Created April 18, 2019 04:54
A trait to control the daily limit of the entity creation
<?php declare(strict_types = 1);
namespace Traits;
use Exception;
use Illuminate\Http\Response;
trait HasDailyLimit
{
@calexandrepcjr
calexandrepcjr / flag_bad_words.php
Last active April 25, 2019 22:17
Flag bad words by a bad words list
<?php
function flagWords($text, $badwords)
{
$badword = reset($badwords);
while ($badword) {
$text = preg_replace(
'/('. preg_quote($badword) .')/i',
'<span style="color:red;">$1</span>',
$text
);
<?php
/**
* This method was created to easily parse any URI helping
* with HTTP Clients requests when adding routes
*
* @param string $uri
* @return string
**/
function uriSanitizer(string $uri): string
{
@calexandrepcjr
calexandrepcjr / bulk_msql_insert_from_csv.txt
Created September 6, 2018 19:03
Bulk Insert into MSSQL CE from CSV with C#
Bulk Insert into MS SQL Compact Edition Database from CSV files using C#
In MS SQL Server, bulk insert into database from CSV files can be easily done by calling 'LOAD' command from SQL query. However, this command is not supported in MS SQL compact edition. By inserting line by line into sqlce database is obviously too slow for most application that consumes large amount of data. Below is a source code written in C# for sqlce which allows users to obtain performance similar to bulk insert in MS SQL Server
public void BulkInsertFromCSV(string file_path, string table_name, string connection_string, Dictionary<string, Type> data_types)
{
string line;
List<string> column_names = new List<string>();
using (StreamReader reader = new StreamReader(file_path))
{
line = reader.ReadLine();
@calexandrepcjr
calexandrepcjr / humble_bundle_books.txt
Last active March 15, 2019 23:41
How to download all the Humble Bundle Books after purchase
# Main inspiration/initial credits: https://gist.github.com/graymouser/a33fbb75f94f08af7e36
# Open the console and run this js:
var pattern = /(MOBI|EPUB|PDF( ?\(H.\))?|CBZ|Download)$/i;
var nodes = document.getElementsByTagName('a');
var downloadCmd = '';
for (i in nodes) {
var a = nodes[i];
if (a && a.text && pattern.test(a.text.trim()) && a.attributes['href']) {
downloadCmd += a.attributes['href'].value + "\"\n";
@calexandrepcjr
calexandrepcjr / Html_helper.php
Created July 26, 2017 18:23
A helper to handle with some HTML tags
<?php
/**
* Builds HTML dropdowns in a simple way
* @param array $array
* @param bool $hasAll
*/
function mountDropdownHtml($array, $hasAll = false)
{
if (!is_array($array)) {
throw new Exception('Invalid argument: First argument must be an array');
@calexandrepcjr
calexandrepcjr / MY_Controller.php
Created July 25, 2017 11:01
Quick idea of blocking external access with PHP
<?php
class MY_Controller
{
private function ipVersion($ip)
{
return strpos($ip, ':') === false ? 4 : 6;
}
public function isLocal()
{