Skip to content

Instantly share code, notes, and snippets.

View scardine's full-sized avatar

Paulo Scardine scardine

View GitHub Profile
@scardine
scardine / postmark.py
Created November 9, 2017 10:34
Use Postmark + requests
import os
from base64 import b64encode
import requests
from django.conf import settings
from django.template.loader import render_to_string
import magic
try:
@scardine
scardine / postmark.py
Created November 9, 2017 10:33
Use Postmark + requests
import os
from base64 import b64encode
import requests
from django.conf import settings
from django.template.loader import render_to_string
import magic
try:

Keybase proof

I hereby claim:

  • I am scardine on github.
  • I am scardine (https://keybase.io/scardine) on keybase.
  • I have a public key ASC9JweFtSgQkSwSXJ-VQnXADDR1vYsbW3NF7D20RmpWYAo

To claim this, I am signing this object:

@scardine
scardine / nfpaulistana.py
Created May 27, 2017 07:27
Classe para emissão de NFe usando o site da prefeitura de SP
# coding=utf-8
import re
import time
from selenium.webdriver import PhantomJS
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
DCAP = dict(DesiredCapabilities.PHANTOMJS)
DCAP.update({
@scardine
scardine / anotacoes.md
Created January 8, 2016 12:53
Recompilar IMP no SEADE

JSX

Para compilar os arquivos JSX:

cd /var/www/html/imp/frontend/js
jsx --watch src/ build/

Uglify

Para publicar em produção:

@scardine
scardine / COREOS.md
Last active December 23, 2015 14:24
CoreOS / Docker

Diagnóstico etcd

Para verificar log:

$ journalctl -u etcd

Para iniciar:

$ systemctl start etcd.service
@scardine
scardine / profiling.md
Last active August 29, 2015 14:11
Iterating over dict keys versus key/value inside a list comprehension when you need access to the value (Python).

From a discussion with Martijn Pieters at stackoverflow

This is meant as a comment, posted as an answer because it is too big for the comment system. Answering to Martijn Pieters:

PauloScardine: but now you are inserting a value lookup each iteration. That's not more efficient. And in this specific case, you'd have to call vars(MyClass) too, or do an extra attribute lookup with MyClass.__dict__

Probably the difference is marginal, but it is always good to profile before claiming some code is more efficient than other, so here we go:

$ python --version

Python 2.7.6

@scardine
scardine / services.js
Created February 6, 2014 21:55
Model definition for Angular+Django rest framework
// https://github.com/blacklocus/angular-django-rest-resource
angular.module('app.services', ['ngResource'], function($provide) {
$provide.factory('ModelName', function($resource) {
return djResource('/v1/model-name/pk:id/', {pk:'@id'});
});
$provide.factory('OtherModelName', function($resource) {
return djResource('/v1/other-model-name/pk:id/', {pk:'@id'});
});
})
@scardine
scardine / header_hack.js
Created February 6, 2014 21:40
Header hack for Django+Angular
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = angular.element.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
@scardine
scardine / rt_permission_cleanup.sql
Last active December 29, 2015 08:59
Delete RT permission that causes too many options at the "Owner" select on Ticket creation screen:
-- Delete any ACL allowing everyone to own ticlets for any queue
DELETE FROM ACL WHERE id IN (
SELECT id FROM ACL WHERE RightName='OwnTicket' AND objecttype='RT::Queue' AND principalid IN (
SELECT id FROM Groups WHERE domain='SystemInternal' AND type='Everyone'
)
);