Skip to content

Instantly share code, notes, and snippets.

@david-torres
david-torres / nginx.conf
Created Nov 18, 2019 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
View nginx.conf
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
View keybase.md

Keybase proof

I hereby claim:

  • I am david-torres on github.
  • I am detour (https://keybase.io/detour) on keybase.
  • I have a public key ASAfJq14-bdH5FUHOCLONuhlQCqd9FDSwoVDIsWT2P4newo

To claim this, I am signing this object:

@david-torres
david-torres / sort_hex.php
Last active Jun 15, 2017
[sort hex] Sort an array of hexadecimal numbers in PHP #php
View sort_hex.php
<?php
$hexValues = array(
dechex(10), // a
dechex(42), // 2a
dechex(111), // 6f
dechex(78), // 4e
dechex(16) // 10
);
usort($hexValues, function($a, $b){
@david-torres
david-torres / db_exists.js
Last active Mar 1, 2018
[mongo db_exists command] MongoDB command to check if a database exists. I use it with a puppet script to conditionally load up a database dump if one isn't detected. Useful for provisioning Vagrant. Returns with exit code zero if the database was found. #mongodb
View db_exists.js
function db_exists(db_name) {
db = db.getSiblingDB('admin');
db.runCommand('listDatabases').databases.forEach(function(db_entry){
if (db_entry.name == db_name) {
// quit with exit code zero if we found our db
quit(0);
}
});
// quit with exit code 1 if db was not found
@david-torres
david-torres / gist:3013369
Created Jun 28, 2012
Hello World using Moai SDK
View gist:3013369
MOAISim.openWindow('test', 320, 480)
viewport = MOAIViewport.new()
viewport:setSize(320, 480)
viewport:setScale(320, 480)
layer = MOAILayer2D.new()
layer:setViewport(viewport)
MOAISim.pushRenderPass(layer)
@david-torres
david-torres / diffbot.py
Created Nov 3, 2011
Simple Python interface for Diffbot API
View diffbot.py
import requests
import json
class Diffbot(object):
"""
A simple Python interface for the Diffbot api.
Relies on the Requests library - python-requests.org
Usage:
@david-torres
david-torres / ClickyApi.py
Created Oct 29, 2011
Simple Python interface for Clicky web analytics API
View ClickyApi.py
import requests
import json
class ClickyApi(object):
"""
A simple Python interface for the Clicky web analytics api.
Relies on the Requests library - python-requests.org
Usage:
@david-torres
david-torres / AmazonSignatureUtil.py
Created Sep 9, 2011
A basic utility class written in Python that verifies an Amazon Simple Payments return url or IPN url using VerifySignature from the FPS API
View AmazonSignatureUtil.py
import base64
import hmac
import hashlib
import urllib
import urllib2
import time
from datetime import datetime, tzinfo
from xml.dom import minidom