Skip to content

Instantly share code, notes, and snippets.

# Select those values, get them to be json
c.execute('select * from data')
data = c.fetchall()
print data
# Data will print: [(u'{"test": "test2"}',)]
# To load the JSON for python use
for item in data:
print json.loads(item[0])
# Data will print: {u'test': u'test2'}
import sqlite3
import json
conn = sqlite3.connect('test.db')
c = conn.cursor()
# Insert {'test':'test2'} dummy values into database
c.execute('''insert into data values(?)''',(json.dumps({'test':'test2'}),))
conn.commit()
@mcescalante
mcescalante / sqlite3json.py
Last active September 22, 2024 19:27
Python SQLite3 INSERT & SELECT for JSON
import sqlite3
import json
conn = sqlite3.connect('test.db')
c = conn.cursor()
# Insert values
c.execute('''insert into data values(?)''', (json.dumps({'test':'test2'}),))
conn.commit()
@mcescalante
mcescalante / keybase.md
Created October 13, 2017 15:06
keybase proof

Keybase proof

I hereby claim:

  • I am mcescalante on github.
  • I am mcescalante (https://keybase.io/mcescalante) on keybase.
  • I have a public key whose fingerprint is 59F6 7311 E003 5EBE 4A0C D3C3 238D 8F30 A94E F114

To claim this, I am signing this object:

@mcescalante
mcescalante / .tmux.conf
Created November 8, 2016 21:07
My OSX/macOS tmux configuration, tested on 10.11.x
#allow mousing
set -g mouse-utf8 on
set -g mouse on
# Return pre-2.1 mousing behaviour
# https://github.com/tmux/tmux/issues/145
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M
# Use vim keybindings in copy mode
@mcescalante
mcescalante / instructions.md
Last active July 25, 2023 14:07
Run a Flask application with gunicorn and nginx

This guide assumes:

  • You have a VPS (something like DigitalOcean, Linode, etc.)
  • You have a Flask application and a basic understanding of command line instructions
  • You've got nginx installed and know where your configuration files are

Instructions

  1. First, you should install gunicorn on your box or virtualenv with pip:
@mcescalante
mcescalante / cx_oracle_install_instructions.md
Last active November 13, 2017 20:46
cx_Oracle installation instructions/notes for macOS or Linux

cx_Oracle Installation Instructions

I've had to put cx_Oracle (python Oracle database connector) on macOS and Linux, and both processes were similar but poorly documented on Oracle's website.

These instructions were written and tested using the client 12.1. The instructions for any 12.x are the same, but you may need to change 12_1 to 12_2 in commands if you are using version 12.2, etc.

Instructions

  1. Download 64 bit (easy to download 32 by mistake) basic + sdk instantclient from Oracle website (Note: you need an account, I used throwaway email)
@mcescalante
mcescalante / lolcomment.css
Created February 24, 2015 00:43
funny css file comment
/*
TODO: Rewrite this from scratch
TODO: Use this code as an example of how not to code:
- no comments
- nondescript var names
- inline html generation
- inline css generation
- not keeping a reference to DOM elements
- browser checks
- code quadruplication (I've never actually seen that before)
@mcescalante
mcescalante / formMacro.html
Created January 29, 2015 17:36
jinja macro for rendering form field errors
{% macro with_errors(field) %}
<div class="form_field">
{% if field.errors %}
{% set css_class = 'has_error ' + kwargs.pop('class', '') %}
{{ field(class=css_class, **kwargs) }}
<ul class="errors">{% for error in field.errors %}<li>{{ error|e }}</li>{% endfor %}</ul>
{% else %}
{{ field(**kwargs) }}
{% endif %}
</div>
@mcescalante
mcescalante / flushcache.sh
Created August 5, 2014 21:51
Flush DNS Cache OSX
#sometimes helpful when reconfiguring /etc/hosts to point locally and browsers are using a cached copy
dscacheutil -flushcache