Skip to content

Instantly share code, notes, and snippets.

View eirikb's full-sized avatar

Eirik Brandtzæg eirikb

  • Softeria AS
  • Ålesund, Norway
View GitHub Profile
@eirikb
eirikb / fast-domdom.tsx
Created August 7, 2020 20:12
FAST + domdom
import domdom from "@eirikb/domdom";
import {
FASTDesignSystemProvider,
FASTButton,
FASTAccordion
} from "@microsoft/fast-components";
const { React, init, on, set, get } = domdom();
FASTDesignSystemProvider;
@eirikb
eirikb / discord-remove-sidepanels.js
Created March 19, 2020 19:07
Remove panels from discord
document.querySelector('*[class^=membersWrap]').style.display = 'none'
document.querySelector('*[class^=sidebar]').style.display = 'none'
const test = require('ava');
const when = require('./when');
const { sp } = require('@pnp/pnpjs');
test('when', t => {
const mySp = when(sp);
mySp.web.getList('web/Lists/A').items.filter(`Title eq 'yes'`).get.thenReturn([{ Id: 1 }]);
mySp.web.getList('web/Lists/A').items.filter(`Title eq 'no'`).get.thenReturn([{ Id: 2 }]);
mySp.web.getList('web/Lists/B').items.filter(`Title eq 'yes'`).get.thenReturn([{ Id: 3 }]);
const fs = require('fs');
const head = () => {
Object.assign(process.env, require('../local.settings').Values);
const orchestrators = {};
console.log.error = console.error;
const context = { log: console.log };
const setInput = input => context.bindings = { input: { input } };
const df = {
orchestrator(cb) {
const isOutlookNative = Office.context.mailbox && Office.context.mailbox.diagnostics.hostName === 'Outlook';
if (isOutlookNative) {
msal.openPopup = () => {
const dummy = {
close() {
},
location: {
assign(url) {
Office.context.ui.displayDialogAsync(url, { width: 25 }, res => {
@eirikb
eirikb / normalize-table.js
Last active January 10, 2020 20:16
DOM normailzation of table rows - creates a matrix with duplicate cells based on rowspan colspan
module.exports = table => {
const res = [];
table.querySelectorAll('tbody tr').forEach((row, y) =>
row.querySelectorAll('td').forEach((cell, x) => {
const rowspan = Number(cell.getAttribute('rowspan') || 1);
const colspan = Number(cell.getAttribute('colspan') || 1);
while (res[y] && res[y][x]) x++;
for (let yy = y; yy < y + rowspan; yy++) {
const resRow = res[yy] = res[yy] || [];
@eirikb
eirikb / 2019-2020-knr-gnr.js
Last active January 7, 2020 13:51
Matrikkel: Oppslag nye kommunenummer (knr) og gårdsnummer (gnr) fra 2019 mot nye i 2020
const data = require('./2019-2020-knr-gnr.json');
/**
* @typedef {Object} Matrikkel
* @property {string} knr - Kommunenummer
* @property {number} gnr - Gårdsnummer
*/
function sanitizeKnr(knr) {
return String(knr || '').padStart(4, '0');
@eirikb
eirikb / 2019-2020-kommuenummer-postnummer.md
Last active January 3, 2020 19:34
2019 2020 kommuenummer postnummer
@eirikb
eirikb / app.js
Last active November 15, 2019 14:58
MSAL in Outlook Add-In
import "core-js/stable";
import "regenerator-runtime/runtime";
import 'whatwg-fetch';
import { UserAgentApplication } from 'msal';
const clientId = '<PUT YOUR CLIENT ID HERE>';
const scopes = ['User.Read'];
const msal = new UserAgentApplication({ auth: { clientId } });
const p = document.querySelector('p');
@eirikb
eirikb / DI.kt
Created September 25, 2019 18:45
package gutsu
import no.eirikb.gutsu.Gutsu
interface PumpService {
fun startPump()
}
class DataDesk {
fun sendMessage(text: String) {