Skip to content

Instantly share code, notes, and snippets.

View michaelaguiar's full-sized avatar
🎯
Focusing

Michael Aguiar michaelaguiar

🎯
Focusing
View GitHub Profile
@michaelaguiar
michaelaguiar / autocomplete.js
Created May 18, 2020 15:29
Google Maps Address Autocomplete
function initAutoComplete() {
var input = document.getElementById("grid-address");
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.addListener("place_changed", function () {
let place = autocomplete.getPlace();
let address = "";
if (place.address_components) {
address = [
@michaelaguiar
michaelaguiar / private.php
Created October 22, 2019 23:15
Laravel validate before downloading private file
<?php
public function downloadFile(Request $request)
{
// !VALIDATE USER HAS ACCESS
// Get response and clean before return
$response = Storage::download(FILE_PATH_HERE);
ob_end_clean();
@michaelaguiar
michaelaguiar / my.cnf
Created August 16, 2019 17:16
Decrease memory consumption of MySQL 5.7
performance_schema = 0
show_compatibility_56 = 1
<?php
/**
* Sell only in specific states
*/
add_filter( 'woocommerce_states', 'wc_sell_only_states' );
function wc_sell_only_states( $states )
{
$states['US'] = [
'AL' => __( 'Alabama', 'woocommerce' ),
'AK' => __( 'Alaska', 'woocommerce' ),
@michaelaguiar
michaelaguiar / select_arrow.css
Created January 22, 2019 22:00
CSS Arrow on Select
background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
background-position: calc(100% - 20px) calc(1em + 2px), calc(100% - 15px) calc(1em + 2px), calc(100% - 2.5em) 0.5em;
background-size: 5px 5px, 5px 5px, 1px 1.5em;
background-repeat: no-repeat;
@michaelaguiar
michaelaguiar / git_work.sh
Created September 27, 2018 20:29
GIT Work Profile alias
git config --global alias.workprofile 'config user.email "[email protected]"'
@michaelaguiar
michaelaguiar / arg.sh
Created August 1, 2018 19:11
Key / Value Arguments in Shell
for i in "$@"
do
case $i in
-o=*|--one=*)
ONE="${i#*=}"
shift
;;
-t=*|--two=*)
TWO="${i#*=}"
shift
@michaelaguiar
michaelaguiar / valdate_email.js
Created June 29, 2017 21:58
Validate Email Address
function validateEmail(email)
{
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
@michaelaguiar
michaelaguiar / convert.php
Created May 22, 2017 18:50
Convert memory_get_usage() to a more readable number
<?php
public function convert($size)
{
$unit = ['b','kb','mb','gb','tb','pb'];
return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
}
?>
@michaelaguiar
michaelaguiar / rename.swift
Created June 7, 2016 00:08
Rename a file in Swift
// Create a FileManager instance
let fileManager = NSFileManager.defaultManager()
// Rename 'hello.swift' as 'goodbye.swift'
do {
try fileManager.moveItemAtPath("hello.swift", toPath: "goodbye.swift")
} catch let error as NSError {
print("Ooops! Something went wrong: \(error)")
}