Skip to content

Instantly share code, notes, and snippets.

View phellipeandrade's full-sized avatar
🏡
Working from home

Phellipe Andrade phellipeandrade

🏡
Working from home
  • São Paulo - Brazil
View GitHub Profile
@phellipeandrade
phellipeandrade / README.md
Created November 6, 2016 14:55 — forked from zenorocha/README.md
A template for Github READMEs (Markdown) + Sublime Snippet

Project Name

TODO: Write a project description

Installation

TODO: Describe the installation process

Usage

@phellipeandrade
phellipeandrade / gist:bb2533e8033dc303dd5e6d75f9e47d27
Created November 7, 2016 12:53
Script de teste de cache.manifest
<script>
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
//The sum of 'weights' elements should be equal 1.
let weights = [0.1, 0.9]; // probabilities
//The possible results
let results = [0, 1]; // values to return
function getRandom () {
let num = Math.random(),
s = 0,
lastIndex = weights.length - 1;
@phellipeandrade
phellipeandrade / install_nodejs_ubuntu.txt
Last active January 15, 2017 19:24
The Best Way to Install Node.js Ubuntu
$ sudo apt-get purge nodejs && sudo apt-get autoremove && sudo apt-get autoclean
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
$ nvm list
$ nvm ls-remote
$ nvm install 6.9.4
$ nvm use 6.9.4
$ nvm alias default 6.9.4
$ node -v
@phellipeandrade
phellipeandrade / mongodb_drop_all_databases.txt
Last active January 22, 2017 12:56
MongoDB drop ALL databases - console
mongo --quiet --eval 'db.getMongo().getDBNames().forEach(function(i){db.getSiblingDB(i).dropDatabase()})'
#!/bin/bash
# Fetch the latest branches
git fetch
# Get the repository path
repoPath=$(git config --get remote.origin.url)
dir=$(pwd)
# Loop through each branch
@phellipeandrade
phellipeandrade / nginxproxy.md
Created May 30, 2017 14:32 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@phellipeandrade
phellipeandrade / mongo_backup.sh
Created September 1, 2017 20:16 — forked from sheharyarn/mongo_backup.sh
Mongodump Shell Script for Cronjob
#!/bin/bash
MONGO_DATABASE="your_db_name"
APP_NAME="your_app_name"
MONGO_HOST="127.0.0.1"
MONGO_PORT="27017"
TIMESTAMP=`date +%F-%H%M`
MONGODUMP_PATH="/usr/bin/mongodump"
BACKUPS_DIR="/home/username/backups/$APP_NAME"
// Based on: https://stackoverflow.com/questions/8584902/get-closest-number-out-of-array
const arr = [360, 375, 414, 768, 1024];
// ES6
const closest = (num, arr) => {
let curr = arr[0];
let diff = Math.abs(num - curr);
for (let i of arr) {
const newDiff = Math.abs(num - i);
/*
Hoje não deixaremos mais ninguém no vácuo no whatsapp
Para utilizar:
- Abra o web.whatsapp.com;
- Abra o console e cole o código que está no gist;
- Aguarde e verá uma mensagem sendo enviada a cada momento que alguém te enviar alguma mensagem.
Confira também como ser chato no whatsapp: https://gist.github.com/mathloureiro/4c74d60f051ed59650cc76d1da0d32da