Skip to content

Instantly share code, notes, and snippets.

View ryanpadilha's full-sized avatar
:octocat:

Ryan Padilha ryanpadilha

:octocat:
View GitHub Profile
@ryanpadilha
ryanpadilha / gist:0b54ea13dd000985ecda8bd5590db384
Created September 17, 2018 19:45 — forked from ehuynh/gist:2572398
Start and Stop Jenkins on OSX
# start
sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist
# stop
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
@ryanpadilha
ryanpadilha / brazilian_phone_mask_with_area_code.js
Created January 6, 2019 00:44 — forked from MauricioMoraes/brazilian_phone_mask_with_area_code.js
Mask for 8 or 9 digit phones in brazilian format with area code (ddd) - Using Jquery.inputmask plugin
// Using jquery.inputmask: https://github.com/RobinHerbots/jquery.inputmask
// For 8 digit phone fields, the mask is like this: (99) 9999-9999
// For 9 digit phone fields the mask is like this: (99) 99999-9999
function setupPhoneMaskOnField(selector){
var inputElement = $(selector)
setCorrectPhoneMask(inputElement);
inputElement.on('input, keyup', function(){
setCorrectPhoneMask(inputElement);
});
@ryanpadilha
ryanpadilha / views.py
Created February 13, 2019 13:09 — forked from reinaldons/views.py
Create CSV on-the-fly with Flask, stream_with_context and SQLAlchemy using generator
from datetime import datetime
from flask import current_app, stream_with_context, Response
from flask_blueprint_acquisition import current_blueprint
from sqlalchemy.sql import compiler
from .blueprints import base_blueprint
from .models import Acquisition, Package, Product, User
@ryanpadilha
ryanpadilha / gist:13114364bc54988fd14136943e19c134
Created February 13, 2019 13:09 — forked from mcxiaoke/gist:b7dcbfdc800b06a5439bb7eb2cd223dd
Returning MySQL query data in a csv file with Flask
## I'm working on a project using Flask to access a database and then
## pass on query data to a client where the data will be graphed
## in the browser.
## I wanted to enable users to retrieve the graph data
## in a csv file after clicking a button on the client.
## This is a generalized version of how I did it:
# imports other than Flask
import csv
from sqlalchemy import create_engine
@ryanpadilha
ryanpadilha / timer.py
Created February 21, 2019 15:01 — forked from jonathan-kosgei/timer.py
Python Decorator to Time a Function
""" A simple decorator that times the duration of a function's execution. More info on Decorators at https://pythonconquerstheuniverse.wordpress.com/2009/08/06/introduction-to-python-decorators-part-1/"""
import timeit
def timer(function):
def new_function():
start_time = timeit.default_timer()
function()
elapsed = timeit.default_timer() - start_time
print('Function "{name}" took {time} seconds to complete.'.format(name=function.__name__, time=elapsed))
return new_function()
@ryanpadilha
ryanpadilha / model_relation_ex.py
Created February 24, 2019 15:05 — forked from kirang89/model_relation_ex.py
Example for many-to-many relationship with extra columns in SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship
engine = sqlalchemy.create_engine('sqlite:///:memory:')
Base = declarative_base()
@ryanpadilha
ryanpadilha / run.py
Created April 4, 2019 14:40 — forked from codeinthehole/run.py
Sample Celery chain usage for processing pipeline
from celery import chain
from django.core.management.base import BaseCommand
from . import tasks
class Command(BaseCommand):
def handle(self, *args, **kwargs):
@ryanpadilha
ryanpadilha / ga.py
Created June 5, 2019 17:15 — forked from canburak/ga.py
blog post: Push data to Google Analytics with Python: https://medium.com/p/pushing-data-to-google-analytics-with-python-80eb9691d61f
"""
Simple proof of concept code to push data to Google Analytics.
Related blog post:
* https://medium.com/python-programming-language/80eb9691d61f
"""
from random import randint
from urllib import urlencode
from urllib2 import urlopen
from urlparse import urlunparse
@ryanpadilha
ryanpadilha / meta-tags.md
Created July 17, 2019 18:42 — forked from lancejpollard/meta-tags.md
Complete List of HTML Meta Tags

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">
@ryanpadilha
ryanpadilha / Validate_cpf_cnpj
Created December 11, 2019 02:14 — forked from fjcunha/Validate_cpf_cnpj
jQuery validator methods to validate cpf and cnpj
jQuery.validator.addMethod("cnpj", function (value, element) {
var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
if (value.length == 0) {
return false;
}
value = value.replace(/\D+/g, '');
digitos_iguais = 1;