Skip to content

Instantly share code, notes, and snippets.

@joshm21
joshm21 / code.gs
Created April 23, 2021 17:48
Google Apps Script - Sheet to Array of Objects
const sheetToObjects = (sheet, headerRow=1) => {
const arrayToObject = (array,headers) => {
return array.reduce((obj,value,index) =>{
return {...obj,[headers[index]]: value}
}, {})
}
const sheetValues = sheet.getDataRange().getValues()
const dataValues = sheetValues.slice(headerRow-1)
@joshm21
joshm21 / us
Created August 27, 2020 15:10
Russian Phonetic (Student, AATSEEL, YaShert, яшерт) Keyboard for Linux
// Navigate to /usr/share/X11/xkb/symbols/us
// Adjust the Russian section to match below and reboot
// Change your keyboard layout to include the "Russian (US, Phonetic)"
// See layout image at http://winrus.com/print_e.htm
// phonetic layout for Russian letters on an US keyboard
// by Ivan Popov <pin@konvalo.org> 2005-07-17
// level3 modifier is a shortcut to the "us" meaning of the keys where
// we place cyrillic letters, handy for accessing the corresponding
@joshm21
joshm21 / parseFacebookFriendPage.js
Last active June 27, 2020 16:52
Parse profile id, vanity, and name from Facebook friends page. Make sure you scroll to bottom first!
function parse() {
let people = document.querySelectorAll("._5qo4");
for (let i = 0; i < people.length; i++) {
const aElement = people[i].querySelector("a._5q6s");
let id = null;
let vanity = null;
if (aElement != null) {
const hovercardLink = aElement.getAttribute("data-hovercard");
const idRegex = new RegExp("^/ajax/hovercard/user.php\\?id=(\\d{1,})&.{1,}", "g");
id = idRegex.exec(hovercardLink)[1];
@joshm21
joshm21 / parseFacebookBirthdaysPage.js
Last active June 27, 2020 17:06
Parse profile link, birthday month, and birthday day from Facebook birthdays page. Make sure you scroll to bottom first!
function parse() {
let people = document.querySelectorAll("._43q7");
for (let i = 0; i < people.length; i++) {
const profile = people[i].childNodes[0].href
const tooltip = people[i].childNodes[0].getAttribute("data-tooltip-content");
const monthRegex = new RegExp("\\((\\d{1,2})/\\d{1,2}\\)$", "g");
const dayRegex = new RegExp("\\(\\d{1,2}/(\\d{1,2})\\)$", "g");
const monthMatch = monthRegex.exec(tooltip);
const dayMatch = dayRegex.exec(tooltip);
const month = monthMatch == null ? null : monthMatch[1];
@joshm21
joshm21 / addFormResponseIdAndUrl.gs
Created April 10, 2020 05:07
On Google Form submission, append the response id and edit response link to the Google Sheet row. Supports rapid form submissions. #google-apps-script #forms
function createFormTrigger() {
var triggerFunctionName = "addFormResponseIdAndUrl_";
deleteAllExistingTriggers_();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
ScriptApp.newTrigger(triggerFunctionName)
.forSpreadsheet(spreadsheet)
.onFormSubmit()
.create();
}
@joshm21
joshm21 / splitRangeIntoRows.gs
Last active April 10, 2020 05:02
Split range into an array of ranges representing the rows of the original range #google-apps-script #range
function splitRangeIntoRows(range) {
const sheet = range.getSheet();
const firstRow = range.getRow();
const lastRow = firstRow + range.getNumRows() - 1;
let rows = [];
for (let rowIndex = firstRow; rowIndex <= lastRow; rowIndex++) {
rows.push(sheet.getRange(`${rowIndex}:${rowIndex}`));
}
return rows;
}