Skip to content

Instantly share code, notes, and snippets.

View joelpalmer's full-sized avatar
🐍

Joel Palmer joelpalmer

🐍
View GitHub Profile
@joelpalmer
joelpalmer / !WCF RESTful services and JavaScript Consumers!
Last active August 29, 2015 14:17
WCF RESTful services and JavaScript consumers for a document management application
WCF RESTful services and JavaScript Consumers
@joelpalmer
joelpalmer / SP2013JSListCode.js
Created March 28, 2015 13:04
SharePoint 2013 client-side base list read code
//We need to run our function only after sp.js file loads
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
function ViewItem()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('<<List Name>>');
@joelpalmer
joelpalmer / AJAXLoadEmpDir.js
Created March 28, 2015 13:08
AJAX loading for employee directory cloud app
$.ajax({
28 type: "GET",
29 url: "EDS/Company.xml",
30 dataType: "xml",
31 success: function (xml) {
32
33 var select = $('#companyDDL');
34
35 $(xml).find('Company').each(function () {
36
@joelpalmer
joelpalmer / GoogleMapsDirecsSvcConsume.js
Created March 28, 2015 13:11
Consuming Google Maps Directions Service
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var sa = new google.maps.LatLng(29.578306, -98.440629);
var mapOptions = {
zoom: 7,
center: sa
@joelpalmer
joelpalmer / CalcBizDays.js
Created March 28, 2015 13:13
Calculating Business Days for media company purchasing app
//Needed By Date Validation
var today = new Date();
today.setHours(0, 0, 0, 0);
var fourDaysFromNow = new Date();
fourDaysFromNow = calcBusinessDays(new Date(), 4);
if (screen.PurchaseRequisition.NeedByDate.toString() == today.toString()) {
alert("You’ve selected today as the delivery date. That may not be a realistic delivery date. Do you want to change the delivery date?\n\nThis delivery date may not be possible. Expediting charges will be applied to the order and billed to your department.");
}
else if (screen.PurchaseRequisition.NeedByDate < fourDaysFromNow) {
@joelpalmer
joelpalmer / gist:40b5d35ad569b057a3fa
Last active August 29, 2015 14:22
Avoid eval if you have a name of an object's function in a string and use array syntax to call it
var funcName = "myfunc";
var thingy = {age:27,
myfunc: function fun() {
console.log("It worked")
}};
thingy[funcName]();
@joelpalmer
joelpalmer / slug
Created June 29, 2015 19:59
Slugging
function slug (text) {
var separator = /[^a-z0-9]+/ig;
var drop = /^-|-$/g;
return text
.replace(separator, '-')
.replace(drop, '')
.toLowerCase();
}
function stamp(date){
@joelpalmer
joelpalmer / array.from.js
Created July 3, 2015 21:01
String.toCharArray()
/* Created by Joel Palmer on 7/3/2015.
ES6 --- FireFox 32+ only as of Created by date
Doc & Polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
*/
//create an array from function arguments
var args = function(){
return Array.from(arguments);
};
@joelpalmer
joelpalmer / Array.prototype.find.js
Created July 6, 2015 16:11
Array.prototype.find() examples
/**
* Created by Joel Palmer on 7/6/2015.
*
* ES6 - FF only as of now
*
* Polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
*/
function isEven(el, idx, array){
return el % 2 == 0;
@joelpalmer
joelpalmer / adapter.ts
Created February 28, 2017 15:39
Adapter Pattern with TypeScript
//target (our payment object interface)
interface IPayment {
id: string;
total: number;
SubmitPayment: Function;
}
//our payment class
class Payment implements IPayment {
public id: string;
public total: number;