Skip to content

Instantly share code, notes, and snippets.

View Fawers's full-sized avatar
💻
Studying and gaming

Fabricio Werneck Fawers

💻
Studying and gaming
View GitHub Profile

Resumo: funções

map, zip, filter e reduce

Diferenças entre Python 2.x e Python 3.x

Em Python 2.x, essas funções devolvem listas enquanto que, em Python 3, devolvem geradores. Para usar estes geradores como listas (assim como em Python 2.x), apenas aplique list ao resultado.
Por exemplo:

@Fawers
Fawers / output.md
Created May 31, 2015 16:33
Regular Expressions everywhere
Number: 1
Start time: 00:00:00,659
End time: 00:00:05,429
Text: aberto no começo do ano a presidenta
dilma perto da correção da tabela do

Number: 2
Start time: 00:00:05,429
End time: 00:00:09,660
function getParams() {
// location.search pega tudo a partir do '?' na url
// .slice(1) remove o '?'
var queryString = location.search.slice(1);
// .split('&') separa o texto pelo caractere &
// 'p1=v1&p2=v2'.split('&') => ['p1=v1', 'p2=v2']
var paramsArray = queryString.split('&');
var params = {}
@Fawers
Fawers / app_extras.py
Last active August 29, 2015 14:24
Python (Django) snippet to update querystrings
# Python (Django) snippet to update querystrings. Can be used to:
# · Replace a value from a querystring key
# · Append a value to a querystring key
# · Remove a value from a querystring key
# · Remove all values from a querystring key
#
# Assuming:
# Python version: 3.x (tested on 3.4)
# Django version: 1.8
# App name: app

Referência rápida para branching

Supondo branch de nome BRANCH

  • Para listar branches remotas:

    • git branch -r
  • Para verificar se existe localmente:

  • git branch

@Fawers
Fawers / parseGET.js
Created December 14, 2015 16:34
Parse GET url parameters and arguments with JS (v2)
function parseGET() {
/*
* Parse url GET parameters and arguments and return them as an object.
* Supports multiple values for a same key.
*
* Examples:
* for ?a=1&b=2
* {a: ["1"], b: ["2"]}
* for ?type=5&type=10
* {type: ["5", "10"]}
  • item 1 [DONE]
  • item 2
  • item 1
  • item 2
@Fawers
Fawers / formatThousands.js
Created March 15, 2016 18:25
Formatting numbers to show thousands separators the RegEx way
Number.prototype.formatThousands = function() {
var asStr = this.toString(),
floatPart = asStr.match(/^\d+(\.\d+)?$/)[1],
re = /^(\d*?)(\d{3})$/;
function loop(n) {
var match = n.match(re);
if (match) {
var head = match[1],
function getCookies() {
var cookies = {};
document.cookie.split(';')
.map(function(item) {return item.split('=');})
.forEach(function(item) {cookies[item[0]] = item[1]});
return cookies;
}
@Fawers
Fawers / brazilian-phone-mask.js
Created April 6, 2016 16:37
Phone mask for Brazilian phone numbers
/* REQUIRES jQUERY */
// Mask for the area code
var patternDDD = /^(\d\d)(.+)/,
// Mask for the de facto number
patternPhone = /^(\d\d)(\d)?(\d{4})(\d{4})$/;
// Sometimes the phone number (especially mobile phones) may have an
// additional digit; hence the optional \d in the second group.
// Change the id below to your id, or class, or whatever.