View getmsgraphaccesstoken.js
async function getMSGraphAccessToken() { | |
var body = { | |
grant_type: 'client_credentials', | |
client_id: process.env.AZURE_APP_ID, | |
client_secret: process.env.AZURE_APP_SECRET, | |
resource: 'https://graph.microsoft.com' | |
}; | |
var responseText = await request('https://login.windows.net/' + process.env.AZURE_TENANT_ID + '/oauth2/token', { method: 'POST', body, format: 'urlencoded' }); |
View azure-function-webhook.js
module.exports = function (azureContext, req) { | |
if (req.query.validationtoken) { | |
azureContext.log('Validation token received: ' + req.query.validationtoken); | |
azureContext.res = { | |
body: req.query.validationtoken, | |
isRaw: true | |
}; | |
azureContext.done(); | |
return; |
View jsom.js
var csomapi = require("csom-node"); | |
// this is an example of Azure Function that connects to SharePoint via JSOM | |
module.exports = function (azureContext, req) { | |
var web; | |
initializeJSOM() | |
.then(ctx => { | |
web = ctx.get_web(); | |
ctx.load(web); |
View get-data-from-excel.js
var fileRelativeUrl = "Shared%20Documents/book1.xlsx"; | |
var sheetName = "Sheet1"; | |
var range = "A1|J45"; | |
var url = _spPageContextInfo.webServerRelativeUrl.replace(/\/$/, '') + "/"; | |
loadXMLDoc(url + "_vti_bin/ExcelRest.aspx/" + fileRelativeUrl + "/model/Ranges('" + sheetName + "!" + range + "')?$format=atom", function (text) { | |
var parser = new DOMParser(); | |
var excelRestNS = 'http://schemas.microsoft.com/office/2008/07/excelservices/rest'; | |
var xmlDoc = parser.parseFromString(text, "text/xml"); | |
var rows = xmlDoc.getElementsByTagNameNS(excelRestNS, 'row'); |
View mc.html
<html> | |
<head> | |
<meta charset="utf8"/> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.15.2/codemirror.min.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.15.2/codemirror.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.15.2/mode/javascript/javascript.min.js"></script> | |
</head> | |
<body> | |
<canvas width="200" height="240"></canvas> | |
<div style="position: absolute; left: 250px; top: 20px; bottom: 0px; right: 0px;"> |
View interactive-ng2.html
<html> | |
<body> | |
<!-- utility libraries used by Angular 2 --> | |
<script src="https://npmcdn.com/zone.js/dist/zone.js"></script> | |
<script src="https://npmcdn.com/reflect-metadata/Reflect.js"></script> | |
<script src="https://npmcdn.com/rxjs/bundles/Rx.umd.js"></script> | |
<!-- Angular 2 bundles --> | |
<script src="https://npmcdn.com/@angular/core/bundles/core.umd.js"></script> |
View lint-demo.ts
import * as ts from 'typescript'; // don't forget to "npm install typescript -g && npm link typescript" | |
var codeToAnalyse = ` | |
function f1() {} | |
var x = 10; | |
function hello() { function hmm() {} } | |
`; | |
var source = ts.createSourceFile("test.ts", codeToAnalyse, ts.ScriptTarget.ES5); |