Skip to content

Instantly share code, notes, and snippets.

View scardine's full-sized avatar

Paulo Scardine scardine

View GitHub Profile
@scardine
scardine / download_certs.py
Created April 22, 2013 21:19
Download dos certificados Raiz da autoridade certificadora brasileira.
import sh
import os
import re
from path import path
home = os.environ['HOME']
p = path.joinpath(home, 'Documents', 'pki', 'nfe', 'certs')
if not p.isdir():
p.makedirs()
@scardine
scardine / check_django_password.php
Last active December 16, 2015 22:49
Check django passwords in PHP (django-1.3)
function check_django_password($plaintext, $hashed) {
$parts = explode('$', $hashed);
if(count($parts) != 3) return FALSE;
if($parts[0] == 'sha1' && sha1($parts[1] . $plaintext)) == $parts[2])
return TRUE;
if($parts[0] == 'md5' && md5($parts[1] . $plaintext)) == $parts[2])
return TRUE;
return FALSE;
}
@scardine
scardine / topojson.py
Created August 23, 2013 14:39
Experiments trying to implement topojson in Python using shapely.
from shapely.geometry import shape, Point, MultiPoint
import math
import json
def get_bounds(geometries):
"""Returns bounding box of geometries. Implementation creates a MultiPoint
from the boxes of all polygons in order to get the result"""
points = []
for g in geometries:
@scardine
scardine / project_name.conf
Last active December 21, 2015 15:29
Django + FCGI + Virtualenv on SUSE/RH. I use Ubuntu, but some customers have annoying policies about linux distros. Can't run Python 2.7 with mod_wsgi because the customer already has another python app using 2.6; my solution was resort to FCGI. Kind of like it, performance is not bad at all.
<VirtualHost *:80>
ServerAdmin admin@project_name.com
ServerName project_name.com
ServerAlias www.project_name.com
# DocumentRoot: not the django project root, just to be safe
DocumentRoot /var/app/project_name/fcgi
# Logs
ErrorLog /var/log/apache2/project_name-error_log
@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'
)
);
@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 / 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 / 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 / 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 / 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: