Skip to content

Instantly share code, notes, and snippets.

View freshlogic's full-sized avatar

Shawn Miller freshlogic

View GitHub Profile
@freshlogic
freshlogic / app.js
Last active March 5, 2024 17:11
HACK: Azure doesn't support X-Forwarded-Proto so we add it manually
var express = require('express');
var app = express();
app.enable('trust proxy');
// HACK: Azure doesn't support X-Forwarded-Proto so we add it manually
app.use(function(req, res, next) {
if(req.headers['x-arr-ssl'] && !req.headers['x-forwarded-proto']) {
req.headers['x-forwarded-proto'] = 'https';
}
@freshlogic
freshlogic / app.js
Last active July 8, 2019 18:53
Check an area code for available Google Voice numbers and post the results to Campfire
var Campfire = require('campfire').Campfire;
var request = require('request');
var areaCode = 972;
var campfire = new Campfire({ ssl: true, token: 'YOUR CAMPFIRE API TOKEN HERE', account: 'YOUR CAMPFIRE SUBDOMAIN NAME HERE' });
var headers = { Cookie: 'YOUR www.google.com COOKIE HERE' };
var url = 'https://www.google.com/voice/setup/searchnew/?ac=' + areaCode + '&start=0&country=US';
request.get({ url: url, headers: headers }, function(error, response, body) {
var json = JSON.parse(body);
var request = require('request');
var sendgrid = require('sendgrid')('YOUR sendgrid.com USERNAME', 'password');
var areaCode = 972;
var headers = { Cookie: 'YOUR www.google.com COOKIE HERE' };
var url = 'https://www.google.com/voice/setup/searchnew/?ac=' + areaCode + '&start=0&country=US';
request.get({ url: url, headers: headers }, function(error, response, body) {
var json = JSON.parse(body);
var message = 'Google Voice: There are ' + json.JSON.num_matches + ' numbers in area code ' + areaCode + ' available at this time.';
@freshlogic
freshlogic / cache.js
Created January 15, 2014 21:53
Returns data from cache if available; otherwise executes the specified function and places the results in cache before returning the data.
var redis = require('redis');
function Cache(port, host, options) {
this.client = redis.createClient(port, host, options);
};
// Returns data from cache if available;
// otherwise executes the specified function and places the results in cache before returning the data.
Cache.prototype.fetch = function(key, func, options, callback) {
// Options are optional
function(game, team1, team2) {
var percentages = {
round5: { 1: 100, 2: 94, 3: 85, 4: 78, 5: 68, 6: 66, 7: 60, 8: 48, 9: 52, 10: 40, 11: 34, 12: 35, 13: 22, 14: 15, 15: 6, 16: 0 },
round4: { 1: 87, 2: 69, 3: 61, 4: 56, 5: 52, 6: 51, 7: 27, 8: 18, 9: 8, 10: 46, 11: 38, 12: 49, 13: 24, 14: 12, 15: 14, 16: 0 },
round3: { 1: 79, 2: 72, 3: 50, 4: 35, 5: 21, 6: 33, 7: 37, 8: 70, 9: 40, 10: 33, 11: 33, 12: 5, 13: 0, 14: 0, 15: 0, 16: 0 },
round2: { 1: 59, 2: 46, 3: 47, 4: 72, 5: 75, 6: 23, 7: 0, 8: 57, 9: 50, 10: 0, 11: 60, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0 },
round1: { 1: 57, 2: 48, 3: 64, 4: 23, 5: 50, 6: 67, 7: 0, 8: 50, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0 },
round0: { 1: 67, 2: 33, 3: 44, 4: 33, 5: 0, 6: 50, 7: 0, 8: 50, 9: 0, 10: 0, 11: 0, 12: 0, 13: 0, 14: 0, 15: 0, 16: 0 }
};
@echo on
cd /d "%~dp0"
if "%EMULATED%"=="true" if DEFINED APPCMD goto emulator_setup
if "%EMULATED%"== "true" exit /b 0
echo Granting permissions for Network Service to the web root directory...
icacls ..\ /grant "Network Service":(OI)(CI)W
if %ERRORLEVEL% neq 0 goto error
@freshlogic
freshlogic / gist:cc7326042e80f29840b4
Last active October 13, 2017 19:24
Web.cloud.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
</appSettings>
<system.web>
<customErrors mode="off" />
<httpRuntime maxQueryStringLength="2097151" maxUrlLength="2097151" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
exports.xForwardedFor = function(req, res, next) {
if (!req.headers['x-forwarded-for']) {
if (req.headers['x-iis-node-remote_addr']) {
req.headers['x-forwarded-for'] = req.headers['x-iis-node-remote_addr'];
}
}
next();
};
@freshlogic
freshlogic / gist:fb9f912b030e0b8307b0
Last active August 29, 2015 14:04
ServiceConfiguration.Cloud.cscfg
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" serviceName="serviceName" osFamily="4" osVersion="*" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
<Role name="WebRole">
<ConfigurationSettings />
<Instances count="2" />
</Role>
<NetworkConfiguration>
<VirtualNetworkSite name="VirtualNetwork" />
<AddressAssignments>
<InstanceAddress roleName="WebRole">
@freshlogic
freshlogic / gist:c2b3de000229a1b05221
Last active August 29, 2015 14:04
ServiceDefinition.csdef
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="example-com" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole" vmsize="Small">
<Certificates>
<Certificate name="example-com" storeLocation="LocalMachine" storeName="CA" />
</Certificates>
<Imports />
<Startup>
<Task commandLine="setup_web.cmd &gt; log.txt" executionContext="elevated">
<Environment>