Skip to content

Instantly share code, notes, and snippets.

View AndersonFirmino's full-sized avatar
🐍
📜 🎼 🎮 🐧 🦆

Anderson Araujo AndersonFirmino

🐍
📜 🎼 🎮 🐧 🦆
View GitHub Profile
@AndersonFirmino
AndersonFirmino / auth.markdown
Created March 3, 2017 06:58 — forked from mlynch/auth.markdown
AngularJS Authentication and CORS

Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.

CORS

CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.

Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.

That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.

@AndersonFirmino
AndersonFirmino / 0_urllib2.py
Created March 1, 2017 13:23 — forked from kennethreitz/0_urllib2.py
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@AndersonFirmino
AndersonFirmino / 0_urllib2.py
Created March 1, 2017 13:23 — forked from kennethreitz/0_urllib2.py
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@AndersonFirmino
AndersonFirmino / rename_git_branch_locally_and_retome.txt
Last active February 28, 2017 15:36 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@AndersonFirmino
AndersonFirmino / utils.js
Created January 16, 2017 21:18
funções de conveniência
/*
* str2bool
* args: strvalue (um valor boleano valido como string: "true"/"false"/"0"/"1")
* return bool
*/
function str2bool(strvalue){
return (strvalue && typeof strvalue == 'string') ? (strvalue.toLowerCase() == 'true' || strvalue == '1') : (strvalue == true);
}
@AndersonFirmino
AndersonFirmino / Selenium.Python.InjectJS.py
Created January 4, 2017 19:00 — forked from anhldbk/Selenium.Python.InjectJS.py
Inject jQuery into Selenium Driver
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.facebook.com/')
with open('jquery-1.9.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) #active the jquery lib
driver.execute_script("$('#email').text('anhld')")
@AndersonFirmino
AndersonFirmino / Cakefile
Last active December 28, 2016 20:14
Super Cakefile - Pronto para compilar e minificar :D
# ** Cakefile Template ** is a Template for a common Cakefile that you may use in a coffeescript nodejs project.
#
# It comes baked in with 5 tasks:
#
# * build - compiles your src directory to your lib directory
# * watch - watches any changes in your src directory and automatically compiles to the lib directory
# * test - runs mocha test framework, you can edit this task to use your favorite test framework
# * docs - generates annotated documentation using docco
# * clean - clean generated .js files
files = [
@AndersonFirmino
AndersonFirmino / web-servers.md
Created December 26, 2016 19:24 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
Simple Ruby Server:
# ruby -run -e httpd -- -p 5000 .
Simple Python 2 Server:
# python -m SimpleHTTPServer
Simple Python 3 Server:
# python -m http.server
@AndersonFirmino
AndersonFirmino / tupperware.py
Created November 17, 2016 13:48 — forked from floer32/tupperware.py
recursively convert nested dicts to nested namedtuples, giving you something like immutable object literals
from UserDict import IterableUserDict
import collections
__author__ = 'github.com/hangtwenty'
def tupperware(mapping):
""" Convert mappings to 'tupperwares' recursively.