Skip to content

Instantly share code, notes, and snippets.

View lordlycastle's full-sized avatar
🤙
Let it Fly!

lordlycastle

🤙
Let it Fly!
View GitHub Profile
@lordlycastle
lordlycastle / SpeaSheetRangeMaskIntersect.gs
Created June 7, 2022 11:34
Can be used to help with determining if two ranges intersect and the intersection range.
const isEnabled = true
const numberOfShiftGroups = 2
function onEdit(event) {
console.log(`Event range: ${event.range.getA1Notation()}`)
if (!isEnabled && event.range.getSheet().getSheetName() !== "Shifts") {
return
}
const speadSheet = SpreadsheetApp.getActiveSpreadsheet()
const shiftsSheet = speadSheet.getSheetByName("Shifts")
SELECT usename AS role_name,
CASE
WHEN usesuper AND usecreatedb THEN
CAST('superuser, create database' AS pg_catalog.text)
WHEN usesuper THEN
CAST('superuser' AS pg_catalog.text)
WHEN usecreatedb THEN
CAST('create database' AS pg_catalog.text)
ELSE
CAST('' AS pg_catalog.text)
class MyClass {
public myProp = 13;
public static readonly myStaticReadOnlyProp = 99;
private myPrivateProp: string | undefined;
constructor() {
this.myPrivateProp = undefined;
}
public myPublicFunction() {
import * as r from 'ramda';
import * as fp from 'fp-ts';
type PickStrings<T> = {
[Key in keyof T]: string extends T[Key] ? T[Key] : never
}
type StringKeysAsValues<T> = {
[Key in keyof T]-?: string extends T[Key] ? Key : never
}
@lordlycastle
lordlycastle / axios-catch-error.js
Created August 11, 2021 08:41 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@lordlycastle
lordlycastle / jq-insert-var.sh
Created August 5, 2021 07:43 — forked from joar/jq-insert-var.sh
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{
@lordlycastle
lordlycastle / PropertyTypeMapper.ts
Last active July 19, 2021 17:50
Creates types that allow you to create a map of properties of certain type of an object. This map is then recognised by compiler to be compatible with object's keys.
/**
* Creates a union type with names of all properties of T where S extends T[Key]
*
* @example
* ```ts
* type T = { a: string; b?: string; c: string | undefined; d: string | null; e: number };
* type StringPropertiesFromT = PropertiesOfType<T, string>; // 'a' | 'b' | 'c' | 'd'
* ```
*/
export type PropertiesOfType<T, S> = {
@lordlycastle
lordlycastle / appScriptNuggets.js
Created April 14, 2021 17:40
Utility functions for AppScript from Google for Sheets. Taken from: https://community.appsheet.com/t/introducing-script-nuggets/41515
*
NAME: SCRIPT NUGGETS
DESCRIPTION: Apps Script functions for use with AppSheet
SETUP: Replace YOUR_SHEET_ID in first line with the sheet Id from the sheet URL
BY: GreenFlux, LLC
*//////////////////////////////////////////////////////////////////////////////////////////////////////
const ss = SpreadsheetApp.openById('YOUR_SHEET_ID');//(id from sheetURL)
@lordlycastle
lordlycastle / Code.gs
Created April 12, 2021 20:50 — forked from erickoledadevrel/Code.gs
Create a Google Calendar event with an attachment in Apps Script
function createEventWithAttachment() {
var driveFileId = '...';
var file = DriveApp.getFileById(driveFileId);
var event = {
summary: 'Test Event with Attachments',
description: 'Woot!',
attachments: [{
fileId: driveFileId,
fileUrl: file.getUrl(),
mimeType: file.getMimeType(),
@lordlycastle
lordlycastle / checkAndHide.gs
Created April 12, 2021 20:30 — forked from erickoledadevrel/checkAndHide.gs
Google Apps Script code to hide a row when a checkbox is checked.
/*
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
var CHECKBOX_COLUMN = 'B';
function onEdit() {
var range = SpreadsheetApp.getActiveRange();
if (range.getA1Notation().split(/\d/)[0] == CHECKBOX_COLUMN &&