Skip to content

Instantly share code, notes, and snippets.

View JLRishe's full-sized avatar

Jimmy Rishe JLRishe

  • Qdabra Software
  • Kyoto, Japan
View GitHub Profile
@JLRishe
JLRishe / ReplaceMulti.cs
Created May 15, 2024 16:13
Perform multiple mutual exclusive string replacements
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
private static string ReplaceMulti(string startString, IEnumerable<(string, string)> replacements)
{
if (!replacements.Any())
{
@JLRishe
JLRishe / index.js
Last active December 11, 2020 04:45 — forked from n1ru4l/index.js
Fetch blob and convert to base64
const fetchBlob = url => fetch(url)
.then(response => response.blob());
const blobToDataURL = blob => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);

Parent elements/nodes

node.parentElement
node.parentNode

Removing children/attributes

@JLRishe
JLRishe / changeWelcomePage.js
Created September 12, 2019 16:54
Change a SharePoint site's welcome page using REST
async function getDigest(webUrl) {
const r = await fetch(webUrl + '_api/contextinfo', {
method: 'POST',
headers: {
accept: 'application/json',
},
});
const j = await r.json();
@JLRishe
JLRishe / modify_sp_web.js
Created July 10, 2019 08:25
Modify SharePoint Web Properties
async function modifyWeb(digest, url, properties) {
const body = JSON.stringify({
{ '__metadata': { 'type': 'SP.Web' } },
properties,
});
return fetch(`${url}/_api/web`, {
method: "POST",
body,
headers: {
@JLRishe
JLRishe / pipe_compose.js
Last active April 24, 2020 08:35
Simple implementation of pipe() and compose()
// (List[A], Number?, Number?) -> [A]
var slice = Function.prototype.call.bind(Array.prototype.slice);
// (A -> B, B -> C, ..., X -> Y, Y -> Z) -> A -> Z
var pipe = function pipe() {
if (arguments.length === 0) { throw new Error('at least one argument required'); }
var f0 = arguments[0];
var fRem = slice(arguments, 1);
@JLRishe
JLRishe / curry.js
Last active August 28, 2020 15:21 — forked from shidhincr/curry.js
ES5 Implementation of function currying
// (Number, ((x0, .., xn) -> y)) -> (x0 -> .. -> xn -> y)
var curryN = (function () {
var slice = Function.prototype.call.bind(Array.prototype.slice);
var bindArr = function (f, arr) {
return f.bind.apply(f, [{}].concat(arr));
};
return function curryN(argCount, func) {
return function fn() {
var args = slice(arguments);
@JLRishe
JLRishe / SetClientSideComponentValues.js
Last active March 6, 2019 08:26
Set and check ClientSideComponentId and ClientSideComponentProperties on fields
var fetchJson = async (url, options) => (await fetch(url, options)).json();
async function getDigest(site) {
const resObj = await fetchJson(site + '/_api/contextinfo', {
method: 'POST',
headers: {
Accept: 'application/json'
},
credentials: 'include'
});