Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View diegoquintanav's full-sized avatar
🐢
Working from home

Diego Quintana diegoquintanav

🐢
Working from home
View GitHub Profile
@diegoquintanav
diegoquintanav / flask-context-shell.md
Created January 25, 2018 16:00
get Flask context
>>> from hello import app
>>> from flask import current_app
>>> app_ctx = app.app_context()
>>> app_ctx.push()
>>> current_app.name
>>> app_ctx.pop()
@diegoquintanav
diegoquintanav / unixpermissions.md
Last active March 31, 2018 19:50
About UNIX permissions

The command $ ls -l, for example, can return a list of the type

total 24
drwxrwxr-x 2 diego diego 4096 feb  2 11:16 logs
drwxrwxr-x 2 diego diego 4096 feb  5 13:42 __pycache__
-rw-rw-r-- 1 diego diego  185 feb  5 13:40 app.py
drwxrwxr-x 2 diego diego 4096 feb  5 13:34 templates
drwxrwxr-x 6 diego diego 4096 feb  2 10:55 venv
-rw-rw-r-- 1 diego diego   64 feb  5 13:41 wsgi.py
@diegoquintanav
diegoquintanav / docker-gists.md
Last active March 31, 2018 19:42
Docker gists

List the container port address

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

where container_name_or_id can be a map of other docker methods, such as

$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -q)
@diegoquintanav
diegoquintanav / sqla_cheatsheet.md
Last active March 16, 2018 20:31
SQLAlchemy gotchas (and headaches) I've dealt with

Define local model class from remote table

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/database1.db'
app.config['SQLALCHEMY_BINDS'] = {'remote': 'sqlite:////tmp/database1.db'}

@diegoquintanav
diegoquintanav / index.html
Last active November 26, 2022 22:28
How to pass variables from html script tags to the react.js DOM
<div id="container" data-stuff="my variable">
<!-- This element's contents will be replaced with your component. -->
</div>
<script>
window.test = "my react test";
window.dumbname = "martin"
// notice that `stuff` is not passed directly, it is passed using `data-stuff="my variable"` through `container.dataset`
</script>
@diegoquintanav
diegoquintanav / install_ngrok.md
Last active March 19, 2024 14:42
install ngrok

About Ngrok

ngrok allows for rapid tunneling, exposing local servers behind NATs and firewalls to the public internet over secure tunnels. More information in https://ngrok.com/

Installing ngrok

ngrok 1.x is unmaintained and its usage is not encouraged. Instead, follow the instructions on https://ngrok.com/download

  1. download the zip file. In my case is for ubuntu_64 16.04
@diegoquintanav
diegoquintanav / ccze_timestamp.md
Created April 5, 2018 20:31
Add time stamps and colors to logs

Appending a timestamp

$ tail -n 10 -f outputfile | xargs -IL date +"%Y%m%d_%H%M%S:L"

Using ccze

$ (tail -n 10 -f outputfile | xargs -IL date +"%Y%m%d_%H%M%S:L") | ccze
@diegoquintanav
diegoquintanav / .vimrc
Created April 7, 2018 17:39
miscellaneous configuration files
set nocompatible " required
filetype off " required
"allow for external clipboard buffers
set clipboard=unnamed
" set numbers on
set nu
@diegoquintanav
diegoquintanav / metaclasses.md
Last active March 25, 2020 09:26
metaclasses

Some examples of metaclasses definitions

Raw, implicit definition

class MetaClass(type): 

    def get_foo(self):
        return self._foo
    
@diegoquintanav
diegoquintanav / mssql_pyodbc_sqlalchemy_flask.py
Last active March 25, 2020 09:24
Build connection string of MSSQL Azure Databases
from flask_sqlalchemy import make_url
from urllib.parse import quote_plus
def build_connection_string(**params):
"""
Return the url for MSSQL Azure DB Instances
"""
connection_string = quote_plus(
("DRIVER={driver};"