Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrei Markeev andrei-markeev

View GitHub Profile
@andrei-markeev
andrei-markeev / getmsgraphaccesstoken.js
Created Mar 14, 2018
Azure Function get MS Graph access token
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' });
@andrei-markeev
andrei-markeev / azure-function-webhook.js
Created Oct 29, 2017
Minimum example for working with SP webhooks from Azure Functions
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;
@andrei-markeev
andrei-markeev / jsom.js
Created Oct 29, 2017
Node.js Azure Functions #spsbcn
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);
@andrei-markeev
andrei-markeev / get-data-from-excel.js
Created Nov 15, 2016
Get data from Excel file stored in SharePoint using Excel REST API
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');
@andrei-markeev
andrei-markeev / mc.html
Last active Mar 25, 2020
Mini IDE for learning how to code, Minecraft theme
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;">
@andrei-markeev
andrei-markeev / interactive-ng2.html
Last active Aug 22, 2016
Single-page interactive Angular2 + Typescript playground (can be used for creating interactive articles and tutorials)
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>
@andrei-markeev
andrei-markeev / lint-demo.ts
Created Jun 1, 2016
Simple lint based on TS compiler API
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);