Skip to content

Instantly share code, notes, and snippets.

View cadu-leite's full-sized avatar
🐍

Carlos C. Leite cadu-leite

🐍
View GitHub Profile
@cadu-leite
cadu-leite / mocks_py_xmletree.py
Created November 3, 2022 18:29
Python XML Etree MOCKs
import unittest
import xml
from unittest.mock import Mock, patch
import modulo1
from modulo1 import get_tag_content
class TestMockXML(unittest.TestCase):
@cadu-leite
cadu-leite / ajax_XMLHttpRequest.js
Last active May 4, 2022 00:30
JavaScript XMLHttpRequest GET and POST forms js - good to go with Django Python
// http://localhost:8080/contact/form/
// oReq.open("GET", "http://localhost:8080/contact/form");
// id_SubmitContact
var container = "header";
var formId = "id-contactform";
var url_post = "/contact/form/"
function callBackLoad(){
@cadu-leite
cadu-leite / get_key_dot_path.py
Last active October 31, 2022 17:40
Nested Dictionary values through dot path
'''
get key values based on dot path
based on dict or json
d = {
'd1': 1,
'd2': {
'a': 2, 'b': 3, },
@cadu-leite
cadu-leite / postgres_queries_and_commands.sql
Created September 12, 2020 15:37 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@cadu-leite
cadu-leite / gist:8236f4c16dc756eb1eb578784b9bdd5e
Created September 7, 2020 21:45 — forked from joshuapowell/gist:e209a4dac5c8187ea8ce
Setup Postgres.app to use PostGIS on OS X

Download and Install Postgres.app

Before we can setup PostGIS we need to have a local version of Postgresql installed and running. The most effecient way to do this is to download and install Postgres.app.

Spatially Enable your Postgres Database

Once Postgres.app is installed in your computers /Applications directory. Open the Terminal and enter the following two commands

psql -d DATABASE_NAME -f /Applications/Postgres.app/Contents/Versions/9.3/share/postgresql/contrib/postgis-2.1/postgis.sql
@cadu-leite
cadu-leite / fswatch_test_python.sh
Last active August 9, 2020 22:23
BASH fswatch for tests python projects
fswatch -l 45 -r . -e ".*" -i "\\.py$" -o | xargs -n1 -I{} python -m unittest
fswatch -l 15 -r . -e ".*" -i "\\.py$" -o | xargs -n1 -I{} python -m unittest --verbose
# "convert"or transform a Json to objet attributes
# converte ou transforma um Json em objeto com atributos
def _json_object_hook(d:Dict):
return namedtuple('X', d.keys(), rename=True)(*d.values())
def json2obj(data_json: str):
return json.loads(data_json, object_hook=_json_object_hook)
import math
s = 'Sample text'

import decimal
dn = decimal.Decimal(math.pi) # a decimal number
fn = math.pi  # a float number

print (f'{s}')
@cadu-leite
cadu-leite / export-google-docs-to-restructured-text.js
Created June 20, 2020 10:33 — forked from simonw/export-google-docs-to-restructured-text.js
Google Apps script to convert a Google Docs document into reStructuredText
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('Convert to .RST')
.addItem('Convert to .RST and email me the result', 'ConvertToRestructuredText')
.addToUi();
}
// Adopted from https://github.com/mangini/gdocs2md by Renato Mangini
// License: Apache License Version 2.0
String.prototype.repeat = String.prototype.repeat || function(num) {
@cadu-leite
cadu-leite / point_shp_2_png.py
Created December 23, 2019 10:06
Draw PNG with points from a shapefile using PIL
import sys
from osgeo import gdal, ogr
from PIL import Image, ImageDraw
# Filename of input OGR file
vector_fn = 'RG2017_rgi_centroids.shp'
# Open the data source and read in the extent
datasource = ogr.Open(vector_fn)