Skip to content

Instantly share code, notes, and snippets.

View davehax's full-sized avatar

Davehax davehax

View GitHub Profile
var getHeaders = new Headers({
'X-RequestDigest': document.getElementById('__REQUESTDIGEST').value,
'Accept': 'application/json; odata=verbose'
})
var getOptions = {
method: 'GET',
headers: getHeaders,
credentials: 'include'
}
var getHeaders = new Headers({
'X-RequestDigest': document.getElementById('__REQUESTDIGEST').value,
'Accept': 'application/json; odata=verbose'
})
var getOptions = {
method: 'GET',
headers: getHeaders,
credentials: 'include'
}
// POST request headers
var postHeaders = new Headers({
'X-RequestDigest': document.getElementById('__REQUESTDIGEST').value,
'Accept': 'application/json; odata=verbose',
'X-HTTP-Method': 'DELETE', // important - ensure DELETE is in all caps
'If-Match': '*'
});
// POST request options
var postOptions = {
function getSchemaDataForCurrentView() {
var webPartKey = '';
var webPartComponent = null;
var schemaData;
// based on the current view id we can find our way to a WPQ<number>SchemaData variable which has the goodies we need to check in it!
// First, get the web part component variable
for (var key in _spWebPartComponents) {
var a = _spWebPartComponents[key];
if (a.storageId && a.storageId == _spPageContextInfo.viewId.replace(/(\{|\})/g, '')) {
// Read these comments first.
// Instructions for installing express here: https://expressjs.com/en/starter/installing.html
// cd into project directory
// run "npm init"
// mash enter until it's finished
// run "npm install express --save"
const express = require("express");
var host = "127.0.0.1";
List<IUser> users = ... // Get users from Azure AD Graph API in C# code
foreach (IUser u in users)
{
// IMPORTANT - Casting from IUser to Microsoft.Azure.ActiveDirectory.GraphClient.User
// gives us the ability to call .GetExtendedProperties();
Microsoft.Azure.ActiveDirectory.GraphClient.User usr = u as Microsoft.Azure.ActiveDirectory.GraphClient.User;
var extProps = usr.GetExtendedProperties();
// ... other includes
// FIRST - npm install pg
var pg = require('pg');
// SECOND - get the full postgresql connection string.
// You'll have to manually split it up into the various components required to build the
// connection config object.
// e.g. the connection string postgres://randomname:bigasspassword@some-host.compute-x.amazonaws.com:5432/lotsofcharacters
@davehax
davehax / resizeAndCoverTargetDimensions.js
Created August 7, 2017 04:27
Javascript function that takes two sets of dimensions, a source set and a target set, and returns a new set of width and height dimensions that covers the target set. i.e. the small edge of the source set is guaranteed to be long edge of the target set, and the other edge will be calculated while maintaining aspect ratio.
// Scale width and height dimensions to cover the screen
function scaleDimensionsToCoverScreen(width, height, targetWidth, targetHeight) {
let scaledWidth = width;
let scaledHeight = height;
let targetRatio = targetWidth / targetHeight;
let imgRatio = width / height;
// If the target is *more* portrait than the image
// we must take targetHeight and calculate the scaledWidth
Yarn:
yarn init <-- spam enter
yarn add webpack webpack-cli webpack-merge css-loader style-loader file-loader html-webpack-plugin uglifyjs-webpack-plugin clean-webpack-plugin babel-core babel-preset-env babel-loader path --dev
or
NPM:
npm init <-- spam enter
npm install webpack webpack-cli webpack-merge css-loader style-loader file-loader html-webpack-plugin uglifyjs-webpack-plugin clean-webpack-plugin babel-core babel-preset-env babel-loader path --save-dev
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
module.exports = {
entry: {
app: "./src/index.js"
},
plugins: [
new CleanWebpackPlugin(["dist"]),