Skip to content

Instantly share code, notes, and snippets.

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

Anderson Araujo AndersonFirmino

🐍
📜 🎼 🎮 🐧 🦆
View GitHub Profile
@AndersonFirmino
AndersonFirmino / linebreak.py
Created November 3, 2016 00:16 — forked from cemk/linebreak.py
Creating linebreaks and paragraphs in Jinja2/Flask à la Django Style
import re
from jinja2 import evalcontextfilter, Markup, escape
@app.template_filter()
@evalcontextfilter
def linebreaks(eval_ctx, value):
"""Converts newlines into <p> and <br />s."""
value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
paras = re.split('\n{2,}', value)
@AndersonFirmino
AndersonFirmino / threading_example.py
Created November 4, 2016 18:42 — forked from sebdah/threading_example.py
Running a background thread in Python
import threading
import time
class ThreadingExample(object):
""" Threading example class
The run() method will be started and it will run in the background
until the application exits.
"""
#!/usr/bin/python
import sys #for cmd line argv
#take command line args as the input string
input_string = sys.argv
#remove the program name from the argv list
input_string.pop(0)
#convert to google friendly url (with + replacing spaces)
@AndersonFirmino
AndersonFirmino / howto-manually-add-trust-cert-to-rubygems.md
Created November 14, 2016 18:21
Workaround RubyGems' SSL errors on Ruby for Windows (RubyInstaller)

SSL upgrades on rubygems.org and RubyInstaller versions

UPDATE 2014-12-21: RubyGems 1.8.30, 2.0.15 and 2.2.3 have been released. It requires manual installation, please see instructions below.


Hello,

If you reached this page, means you've hit this SSL error when trying to

@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.
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 / 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
@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 / 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 / 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);
}