Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bencooper222's full-sized avatar
👋

Benjamin Cooper bencooper222

👋
View GitHub Profile
@bencooper222
bencooper222 / sumdigits.js
Created October 8, 2017 08:05
Counting the number of occurrences of each parity among a range of adjacent integers
let start = 1;
let end = 123456789;
let evenCount = 0;
let oddCount = 0;
for (let i = start; i <= end; i++) {
if (isEven(sumDigits(i))) {
evenCount++;
@bencooper222
bencooper222 / geocode.gs
Last active April 4, 2017 22:14
Google Sheets Geocoding Custom Function
// returns latlng from Google API
function GEOCODE(input){
var data = JSON.parse(queryGoogle(input));
var location = data.results[0].geometry.location;
return location.lat + ", " + location.lng;
}
@bencooper222
bencooper222 / google_sheets_geocode.gs
Last active April 4, 2017 21:38
This script calls the Google Maps geocoding API, gives locations and returns their "locality, province/state" strings. It's a bit glitchy on certain addresses but should meet the bulk of your needs
// this is designed for a 2 columns, n rows range with the addresses in column with index 0
var addresses = SpreadsheetApp.openByUrl("YOUR URL HERE").
getSheetByName("Assignments").getRange("YOUR RANGE HERE").getValues(); // there are several formats for range - your choice
//Logger.log(addresses[0][1])
function searchJson(data){
data = JSON.parse(data);
@bencooper222
bencooper222 / GetJot.cs
Created March 18, 2017 02:34
Checks if IHSA JOT semi-finals change. Makes synchronous GET requests and checks if it ever changes.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Media;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace GetJot
@bencooper222
bencooper222 / code.js
Created December 12, 2016 01:08
Easy Google Apps Script Secret Santa code given a spreadsheet with names in the B column and emails in the C column
var ss = SpreadsheetApp.getActiveSpreadsheet(); // this is meant to run inline google appsscript - you'll have to use a different get method if you don't want that
var sheet = ss.getSheets()[0]; // assumes sheet 1
var names = sheet.getRange(2,2,sheet.getLastRow()-1,2).getValues();
Logger.log(names);
if (names.length % 2 != 0) {
//alert("You must have an even number of names. You currently have " + names.length + " names.");
} else {
@bencooper222
bencooper222 / add_image_onclick.js
Created September 18, 2016 20:40
Adds image anywhere on a webpage at every location someone clicks.
function createImage(coordinates){
var xPos = coordinates[0];
var yPos = coordinates[1];
var image = document.createElement("img");
image.src = ;// add image file reference here
// set their position
image.style.top = yPos + "px";
image.style.left = xPos + "px";
@bencooper222
bencooper222 / superlative_creator.gs
Created September 1, 2016 06:17
Creates a superlative form for a set of names
function myFunction() {
var form = FormApp.create("Superlatives");
var array = // PUT YOUR NAMES HERE
for(var i = 0; i<array.length; i++){
var item = form.addParagraphTextItem();
item.setTitle(array[i]);
}
Logger.log(breakUpString("hello,goodbye"));
@bencooper222
bencooper222 / Check_checkboxes_squirrelmail.js
Last active August 12, 2016 16:07
Selects all messages on Squirrelmail to allow for easy deleting on servers that have quotas (was designed to work with the student and alumni squirrelmail at IMSA)
var inputs = document.getElementsByTagName("input");
var checkboxes = [];
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
checkboxes[checkboxes.length] = inputs[i];
}
}
private string doThis(){
return kek;
}