Skip to content

Instantly share code, notes, and snippets.

@joseph-aylor
joseph-aylor / EnumMapper.ts
Created July 14, 2017 21:00
Class to Map Enums (good for radio buttons)
export class EnumMapper {
static ToNameValue = function (enumType) {
let names: any[] = [];
for(let n in enumType) {
if(typeof enumType[n] === 'number') {
names.push({name: n, value: enumType[n]});
}
}
return names
}
@joseph-aylor
joseph-aylor / password_auth.sh
Last active March 23, 2017 18:03
Nginx Basic Authentication
sudo apt-get update;
sudo apt-get install apache2-utils;
sudo sh -c "echo -n 'topic:' >> /etc/nginx/.htpasswd";
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd";
sudo htpasswd -c /etc/nginx/.htpasswd topic
# if you come back to add more, leave out the -c
# add the following 2 lines to your nginx config (at the location or server level)
# auth_basic "Restricted Content";
# auth_basic_user_file /etc/nginx/.htpasswd;
import xlrd
def exceltodict(filename, sheetindex, rowstoskip):
workbook = xlrd.open_workbook(filename)
worksheet = workbook.sheet_by_index(sheetindex)
columnnames = []
for col in range(worksheet.ncols):
@joseph-aylor
joseph-aylor / gist:ece72c3686c215ad3e6f
Created August 11, 2014 19:50
When installing nginx from source, here's a file to set it up as a service. Put this in /etc/systemd/system/nginx.service
[Unit]
Description=Nginx
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/opt/nginx/sbin/nginx
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/opt/nginx/sbin/nginx -s reload
@joseph-aylor
joseph-aylor / gist:10158837
Created April 8, 2014 17:22
It's 4pm on a Friday. The client just released a new website yesterday. Now all of digital marketing's links are broken for their local listings. I need to be able find which ones are 404, and which have a 301. If they do have a 301 marketing needs to update their ads. Unleash the Perl.
use warnings;
use strict;
use LWP::UserAgent;
use Try::Tiny;
#This will go to the url, and tell you where you land after following
#any redirects
sub newUrl {
my $oldUrl = shift;
@joseph-aylor
joseph-aylor / Calls From Callsource API Example
Last active November 8, 2017 16:05
Get calls from the Call Source API.
import xml.etree.ElementTree as ET
import requests
from datetime import datetime
from hashlib import md5
def fetchcalldata(startdate, enddate, username, password):
"""
Returns XML representing all calls in the defined date range
Params:
startdate - The beginning of the date range