This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // int -> float | |
| module.exports = (value) => parseFloat((value / Math.pow(10, 2)).toFixed(2)) | |
| // float -> int | |
| module.exports = (value) => parseInt(Math.floor(0.5 + parseFloat(value) * 100)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function distance (lat1, lon1, lat2, lon2, unit = 'K') { | |
| if (lat1 === lat2 && lon1 === lon2) { | |
| return 0 | |
| } | |
| const radlat1 = (Math.PI * lat1) / 180 | |
| const radlat2 = (Math.PI * lat2) / 180 | |
| const theta = lon1 - lon2 | |
| const radtheta = (Math.PI * theta) / 180 | |
| let dist = | |
| Math.sin(radlat1) * Math.sin(radlat2) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ref http://pauldeardorff.com/2013/08/14/handling-currencies-in-ruby-on-rails-apps/ | |
| # db/migration/ | |
| class AddPriceToProducts < ActiveRecord::Migration | |
| def change | |
| add_column :products, :price_in_cents, :integer | |
| add_column :products, :currency, :string | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A Figura 1 representa o grafo de dependência entre módulos de um sistema. A aresta indica | |
| # A relação de dependência entre dois módulos indicada pelo sentido, por exemplo: 1 2, | |
| # indica que o módulo 1 é uma dependência do modulo 2 (ou o modulo 2 depende de 1), ou | |
| # seja, para carregar o modulo 2 precisamos primeiro carregar o modulo 1. | |
| # Implemente um algoritmo em Ruby ou Javascript (Node) que retorne a ordem correta de | |
| # carregamento de todos os módulos do sistema. | |
| class Graph | |
| attr_reader :graph, :nodes, :visited, :sort_nodes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Dado o grafo da Figura 2, implemente um algoritmo em Ruby ou Javascript (Node) que | |
| # encontre o caminho de menor custo a partir de um nó de origem. Imprima o shortest_pathsado do | |
| # custo e o caminho calculado a partir do vértice 0 para todos os outros no seguinte formato: | |
| # node, Cost, Path -> 1, 2, 0-1 | |
| # Principal referência | |
| # https://en.wikipedia.org/wiki/Dijkstra's_algorithm | |
| class Graph | |
| attr_reader :graph, :nodes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| REPO="[email protected]:org/repo.git" | |
| DIST="/home/USER/apps/" | |
| # Create folder if does not exist | |
| if [ -d "$DIST" ]; then | |
| cd $DIST | |
| else | |
| mkdir -p $DIST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # TESTED IN MACOS | |
| # make hook executable | |
| # chmod +x .git/hooks/commit-msg | |
| # get current branch | |
| BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param $str | |
| * @return mixed | |
| */ | |
| function sanitizeString($str) { | |
| $str = preg_replace('/[áàãâä]/ui', 'a', $str); | |
| $str = preg_replace('/[éèêë]/ui', 'e', $str); | |
| $str = preg_replace('/[íìîï]/ui', 'i', $str); | |
| $str = preg_replace('/[óòõôö]/ui', 'o', $str); | |
| $str = preg_replace('/[úùûü]/ui', 'u', $str); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # general variables | |
| _user=$(whoami) | |
| _pwd=$(pwd) | |
| _prefix="[APP]" | |
| # symbolic link for keep ref anywhere | |
| echo "$_prefix Creating symbolic link 'app' on /usr/local/bin/ path..." | |
| if [[ $_user != "root" ]]; then |
NewerOlder