Skip to content

Instantly share code, notes, and snippets.

View vcatalano's full-sized avatar

Vincent Catalano vcatalano

  • Salus Fintech
  • Tucson, AZ
View GitHub Profile
@lmakarov
lmakarov / lambda-basic-auth.js
Created August 30, 2017 19:15
Basic HTTP Authentication for CloudFront with Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
@rpgreen
rpgreen / master.vm
Created February 23, 2016 00:02
API Gateway "Send Everything" Mapping Template
## API Gateway "Send Everything" Mapping Template - Ryan Green - ryang@ryang.ca
## See http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
#set($allParams = $input.params())
{
"body-json" : "$input.json('$')",
"params" : {
#foreach($type in $allParams.keySet())
#set($params = $allParams.get($type))
"$type" : {
#foreach($paramName in $params.keySet())
@martijnvermaat
martijnvermaat / server.py
Created February 5, 2016 17:43
SimpleHTTPServer with history API fallback
#!/usr/bin/env python
"""
Modification of `python -m SimpleHTTPServer` with a fallback to /index.html
on requests for non-existing files.
This is useful when serving a static single page application using the HTML5
history API.
"""
@tzachz
tzachz / H2JDBIRule.java
Last active March 20, 2020 23:01
Dropwizard JDBI JUnit Rule using H2 by default - based on https://gist.github.com/yunspace/9a50e11dbd8661271220
import com.codahale.metrics.MetricRegistry;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Environment;
import liquibase.Liquibase;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.LiquibaseException;
import liquibase.resource.ClassLoaderResourceAccessor;
import org.junit.rules.ExternalResource;
@carljm
carljm / db.py
Last active May 1, 2023 00:54
SQLAlchemy and Postgres autocommit
"""
SQLAlchemy, PostgreSQL (psycopg2), and autocommit
See blog post: http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
"""
from contextlib import contextmanager
from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker, Session as BaseSession
@kyledrake
kyledrake / ferengi-plan.txt
Last active April 6, 2024 00:30
How to throttle the FCC to dial up modem speeds on your website using Nginx
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
@st4lk
st4lk / mandrill_email.py
Last active August 2, 2021 05:31
Python: send emails by mandrill. Django and standalone example
"""
Example of mandrill service in python (http://mandrill.com/)
Description of usage in python:
Russian: http://www.lexev.org/2014/send-email-django-project-mandrill-service/
English: http://www.lexev.org/en/2014/send-email-django-project-mandrill-service/
"""
# ======
# Django
@JedWatson
JedWatson / 1-proposal.md
Last active January 2, 2024 17:59
Proposal: adding reverse-relationship population to Mongoose (as implemented in KeystoneJS)

I've developed a useful feature in KeystoneJS that lets you populate a relationship from either side, while only storing the data on one side, and am looking for feedback on whether it is something that could / should be brought back into mongoose itself. (It might be possible to add as a separate package but I suspect there'd be too much rewriting of mongoose internals for that to be a good idea).

I've added this as an issue in mongoose for consideration: #1888 but am leaving this gist in place because the examples are easier to read.

I've used Posts and Categories as a basic, contrived example to demonstrate what I'm talking about here; in reality you'd rarely load all the posts for a category but there are other real world cases where it's less unreasonable you'd want to do this, and Posts + Categories is an easy way to demo it.

The problem

The built-in population feature is really useful; not just for

@nnarhinen
nnarhinen / Gruntfile.js
Last active February 11, 2020 09:39
Support html5 pushState (or angular.js html5mode) in a yeoman (grunt-contrib-connect) application.
module.exports = function (grunt) {
// show elapsed time at the end
require('time-grunt')(grunt);
// load all grunt tasks
require('load-grunt-tasks')(grunt);
//MODIFIED: add require for connect-modewrite
var modRewrite = require('connect-modrewrite');
grunt.initConfig({
@vpicavet
vpicavet / node_edges.sql
Last active December 24, 2023 18:17
Generate a network geometry edge table in PostGIS according to a edge table and topology relations (to/from nodes) - with triggers
/*
Vincent Picavet <vincent.picavet@oslandia.com>
Work distributed under MIT Licence.
Automated generation of edges geometries according to topology and nodes geometry
A nodes table and a edges table design a network.
Edges are straight lines between id_from and id_to nodes