Skip to content

Instantly share code, notes, and snippets.

View matheus-santos's full-sized avatar
🏠
Working from home

Matheus Santos matheus-santos

🏠
Working from home
View GitHub Profile
@matheus-santos
matheus-santos / regex_rules.md
Last active December 30, 2020 12:16
Useful regex rules

To find component occurrences in imports:

import \{?([A-Za-z0-9\s,]+)\n?\}? from '@\/components

To validate e-mail:

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
# TDD good habits
## Principles
- tests should test one thing only
- test one logical assertion
- don't mix assertions of state and collaboration in the same test
- modifications of production code should only break related test cases
- each test should be self-contained, including data
- ensure tests are independent of each other
- don't refactor with a failing test
@matheus-santos
matheus-santos / inject_key_in_object.md
Last active May 21, 2019 13:18
Regex to add key name as value of property 'id' in object
Search: /^    ([a-zA-Z]+): {\n( +)/
Replace: /    $1: {\n$2id: '$1',\n$2/

Example:

{                             =>   {
 name: {                      =>     name: {
 property1: 'Property 1' => id: 'name', // Added
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
@matheus-santos
matheus-santos / install_mysql.md
Last active May 6, 2019 17:36
Install mysql Mac

Used brew's remove & cleanup commands, unloaded the launchctl script, then deleted the mysql directory in /usr/local/var, deleted my existing /etc/my.cnf (leave that one up to you, should it apply) and launchctl plist

Updated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.

Step-by-step:

brew remove mysql
brew cleanup
launchctl unload -w /usr/local/Cellar/mysql/8.0.16/homebrew.mxcl.mysql.plist
@matheus-santos
matheus-santos / duplicate_row_in_mysql.sql
Last active October 11, 2018 21:22
Duplicate row in MySQL
-- Replace `{{TABLE_NAME}}` to desired table
-- Replace `{{ID}}` to desired row you want to replace
create temporary table `temp` select * from `{{TABLE_NAME}}` where id = {{ID}};
update `temp` SET id = (select id from {{TABLE_NAME}} order by id desc limit 1) + 1 where id = {{ID}};
insert into `{{TABLE_NAME}}` select * from `temp`;
drop TEMPORARY table if exists `temp`;
@matheus-santos
matheus-santos / lodash__black_list_white_list.js
Created October 2, 2018 12:59
Lodash: Delete unwanted properties from the javascript object
You can approach it from either a white list or black list way:
// Black list
// Remove the values you don't want
var result = _.omit(credentials, ['age']);
// White list
// Only allow certain values
var result = _.pick(credentials, ['fname', 'lname']);
If it's reusable business logic, you can partial it out as well:
@matheus-santos
matheus-santos / 01_add_cors.config.yaml
Created October 1, 2018 11:26 — forked from vsviridov/01_add_cors.config.yaml
Add CORS to Nginx on AWS Elastic Beanstalk
container_commands:
01_fix_static_cors:
command: "/tmp/fix_static_cors.sh"
files:
"/tmp/fix_static_cors.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
@matheus-santos
matheus-santos / get_query_log.php
Last active March 4, 2019 13:00
See last executed queries in Laravel
\DB::enableQueryLog();
// Laravel query operation here ...
print_r(\DB::getQueryLog()); exit;
@matheus-santos
matheus-santos / vagrant + docker + windows 10.md
Created October 17, 2016 23:50 — forked from eibreans/vagrant + docker + windows 10.md
Passo a passo docker rodando sobre o vagrant no windows 10

A ideia é ter um Linux virtualizado no windows, que dê para rodar o docker e usar o vagrant como um sistema sobre o Windows. Para não precisar de fazer dual boot, já que tudo o que eu preciso é um terminal Linux que eu posso instalar qualquer coisa com apt-get :)

  1. Instalar no windos o cmder, um emulador de console http://cmder.net/

  2. Instalar virtual box https://www.virtualbox.org/wiki/Downloads

  3. Instalar o vagrant