Skip to content

Instantly share code, notes, and snippets.

View manvillej's full-sized avatar

Jeff Manville manvillej

View GitHub Profile
@manvillej
manvillej / SlashSNResponse
Last active June 19, 2017 15:04
the code for a business rule to respond to a slash command
(function executeRule(current, previous /*null when async*/) {
var slack = new SlackMessage();
slack.endpoint = current.u_response_url;
var response = slack.send("This application is prototype application to integrate Slack's slash commands & ServiceNow ");
// Show error message if it failed
if(response.getStatusCode() != 200) {
gs.addInfoMessage("response.getBody: " + response.getBody());
gs.addInfoMessage("response.getStatusCode: " + response.getStatusCode());
(function process(g_request, g_response, g_processor) {
var app = "slack slash";
var tablename = "u_slash_commands";
var record = new GlideRecord(tablename);
record.setValue("u_method",g_request.getMethod());
record.setValue("u_querystring",g_request.getQueryString());
var urlParamList = g_request.getParameterNames();
while(urlParamList.hasMoreElements()){
@manvillej
manvillej / logging REST call
Created June 19, 2017 15:02
processor script to log parameters & headers of API call
(function process(g_request, g_response, g_processor) {
gs.log("slack method string: "+g_request.getMethod());
gs.log("slack query string: " + g_request.getQueryString());
var urlParamList = g_request.getParameterNames();
var paramMsg = ""; //we're going to log parameter log here
while(urlParamList.hasMoreElements()){
var param = urlParamList.nextElement();
var value = g_request.getParameter(param);
@manvillej
manvillej / Matplot with Axes (python)
Last active October 9, 2017 18:48
Basic example of using axes in python. X is data from a png image. Xrecovered is the compressed image.
import matplotlib.pyplot as plt
# Display the original image
f, (ax1, ax2) = plt.subplots(1,2)
ax1.imshow(X)
ax1.set_title('Original')
ax2.imshow(XRecovered)
ax2.set_title('Compressed')
@manvillej
manvillej / Kmeans algorithm (python)
Last active October 9, 2017 18:48
Short Kmeans Example from Sklearn
from sklearn.cluster import KMeans
K=3 # number of clusers
# setting random_state to 0 seeds random number generate to get
# the same results every run. X is the a MxN matrix where N is the number of features
# and M is the number of examples.
kmeans = KMeans(n_clusters=K, random_state=0).fit(X)
# location of centroids
@manvillej
manvillej / Load .mat with Scipy.io (python)
Created October 9, 2017 18:51
load data and log keys from .mat file using Scipy.io
import scipy.io as io
mat = io.loadmat('./data/ex7data1.mat')
print(mat.keys())
# X = mat['X']
@manvillej
manvillej / Randomly Select Data - (python)
Created October 10, 2017 03:13
Random selection of rows using Numpy
import numpy as np
perm = np.random.permutation(m)
sel = X[perm[0:100],:]
@manvillej
manvillej / Python Print
Created October 11, 2017 21:11
putting examples of python print in one location!
'{}'.format(data) #plain
'{:.2f}'.format(data) #float to 2 decimal places
'{:.2e}'.format(data) #scientific notation to 2 decimal places
@manvillej
manvillej / Inverse mapping of dictionary - (python)
Created October 16, 2017 14:36
reverse the mapping of a dictionary
invDict = {v: k for k, v in dictionary.items()}
@manvillej
manvillej / gist:245db964ff09e8d38679f317e4f67ca2
Created December 14, 2017 16:46
Adding Tasks to Async loop
import asyncio
import time
class human:
def __init__(self, name):
""" """
self.name = name
self.time = 2