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])+)\])
@matheus-santos
matheus-santos / kill_them_all.sh
Created September 10, 2015 15:19
Script that kill slow processes running into Mysql DB
#!/bin/sh
# Author: Matheus Cesário <mts.cesario@gmail.com>
# Description: Killing all slow queries from bd
# Example: sh kill_them_all.sh -s 100
# Variables
SECONDS=0 # Seconds
USER="" # DB user
PASSWORD="" # DB password
HOST="" # DB host
# 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' =&gt; id: 'name', // Added
@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
#
# 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 / cheat_sheet_socketio
Last active May 1, 2019 19:23
SocketIO cheat sheet to emit messages through sockets
// SocketIO cheat sheet
// SocketIO is a library that makes websockets communications easier.
// Page: http://socket.io/
// ref: http://stackoverflow.com/a/10099325
// send to current request socket client
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.sockets.emit('message', "this is a test");
@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 / banks_BR.json
Created April 13, 2016 15:32
Lista de bancos que operam no Brasil
[
{
"code": "001",
"name": "Banco do Brasil",
"short_name": "BB",
"jurisdiction": "Federal",
"website": "www.bb.com.br"
},
{
"code": "002",
@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`;