Skip to content

Instantly share code, notes, and snippets.

View andrei-markeev's full-sized avatar

Andrei Markeev andrei-markeev

View GitHub Profile
@andrei-markeev
andrei-markeev / getmsgraphaccesstoken.js
Created March 14, 2018 09:57
Azure Function get MS Graph access token
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 October 29, 2017 10:43
Minimum example for working with SP webhooks from Azure Functions
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 October 29, 2017 09:55
Node.js Azure Functions #spsbcn
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 November 15, 2016 10:09
Get data from Excel file stored in SharePoint using Excel REST API
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 March 25, 2020 00:28
Mini IDE for learning how to code, Minecraft theme
<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 August 22, 2016 07:34
Single-page interactive Angular2 + Typescript playground (can be used for creating interactive articles and tutorials)
<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 June 1, 2016 09:45
Simple lint based on TS compiler API
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);