Skip to content

Instantly share code, notes, and snippets.

View rcubarocha's full-sized avatar

Roberto Cuba Rocha rcubarocha

View GitHub Profile
@rcubarocha
rcubarocha / app.js
Created November 15, 2019 02:15 — forked from joshnuss/app.js
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./permission"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@rcubarocha
rcubarocha / test_flask.py
Created July 13, 2017 23:51 — forked from taudep/test_flask.py
Sample Flask Python server
from flask import Flask, g, request, flash, url_for, redirect, render_template, abort
from flaskext.jsonify import jsonify
from flaskext.sqlalchemy import *
from sqlalchemy import *
from pyodbc import *
import logging
DATABASE = "dsn=Foo;Trusted_Connection=Yes"
SECRET_KEY = "asdasdfasd1234sdagfa23asdfg123"
@rcubarocha
rcubarocha / rbenv-howto.md
Created October 7, 2016 16:54 — forked from MicahElliott/rbenv-howto.md
Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

Setting up and installing rbenv, ruby-build, rubies, rbenv-gemset, and bundler

This guide enables you to install (ruby-build) and use (rbenv) multiple versions of ruby, isolate project gems (gemsets and/or bundler), and automatically use appropriate combinations of rubies and gems.

TL;DR Demo

# Ensure system is in ship-shape.

aptitude install git zsh libssl-dev zlib1g-dev libreadline-dev libyaml-dev

@rcubarocha
rcubarocha / install-comodo-ssl-cert-for-nginx.rst
Created June 29, 2016 03:13 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@rcubarocha
rcubarocha / backbone_pushstate_router.js
Created June 28, 2016 18:08 — forked from tbranyen/backbone_pushstate_router.js
hijack links for pushState in Backbone
// All navigation that is relative should be passed through the navigate
// method, to be processed by the router. If the link has a `data-bypass`
// attribute, bypass the delegation completely.
$(document).on("click", "a[href]:not([data-bypass])", function(evt) {
// Get the absolute anchor href.
var href = { prop: $(this).prop("href"), attr: $(this).attr("href") };
// Get the absolute root.
var root = location.protocol + "//" + location.host + Application.root;
// Ensure the root is part of the anchor href, meaning it's relative.
@rcubarocha
rcubarocha / test.py
Created June 23, 2016 05:19 — forked from mrjoes/test.py
How to customize options in QuerySelectField. High level idea: 1. Hook `create_form` to change options when creating model and `edit_form` when editing model 2. Provide different `query_factory` for the field 3. Do filtering/population logic in the _get_parent_list Alternatively: 1. Can hook `scaffold_form` and change `form.parent.kwargs['query_…
from flask import Flask, request, url_for
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.admin.contrib import sqlamodel
from flask.ext import admin
# Create application
app = Flask(__name__)
# Create dummy secrey key so we can use sessions
@rcubarocha
rcubarocha / CalculatorView.swift
Created January 20, 2016 07:19 — forked from natecook1000/CalculatorView.swift
An IBInspectable Calculator Construction Set
// CalculatorView.swift
// as seen in http://nshipster.com/ibinspectable-ibdesignable/
//
// (c) 2015 Nate Cook, licensed under the MIT license
/// The alignment for drawing an String inside a bounding rectangle.
enum NCStringAlignment {
case LeftTop
case CenterTop
case RightTop