Skip to content

Instantly share code, notes, and snippets.

View scolton99's full-sized avatar
🐢

Spencer Colton scolton99

🐢
  • Northwestern University
  • Chicago, IL
View GitHub Profile
@scolton99
scolton99 / 2030_1824.js
Created March 10, 2021 21:25
Guide generation for Photoshop to mark the 18" x 24" bounds of an element at the center of a 20" x 30" document (works with anything of these aspect ratios).
const [_1, _2, inx, iny] = process.argv;
const sizediffh = (inx - ((24/30) * inx));
const guidel = (1/2) * sizediffh;
const guider = inx - (1/2) * sizediffh;
const sizediffv = (iny - ((18/20) * iny));
const guidet = (1/2) * sizediffv;
const guideb = iny - (1/2) * sizediffv;
@scolton99
scolton99 / modulo.c
Created March 12, 2021 05:51
Demonstration of timing of C modulo vs. truncated division modulo.
long mod();
long mod_div();
int main() {
mod();
mod_div();
return 0;
}
long mod() {
@scolton99
scolton99 / shift_vs_add.c
Created March 16, 2021 06:04
Demonstration of time spent using shift operation vs an add operation.
long add_a();
long shift_a();
int main() {
add_a(5);
shift_a(5);
return 0;
}
long add_a(int a) {
@scolton99
scolton99 / Permuter.java
Created May 5, 2021 00:08
A terrible, horrible, no-good, very bad Java class to permute the elements of a list. Does not use memory well.
package tech.scolton.util;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
public class Permuter<T> {
public List<List<T>> permute(Collection<T> rem) {
@scolton99
scolton99 / TechInterviewDriver.java
Created May 24, 2021 22:02
My solution to the Item Frequency problem.
package tech.scolton.jordan;
import java.util.*;
public class TechInterviewDriver {
public static void main(String[] args) {
String[] input = new String[]{"apple", "apple", "orange"};
Map<String, Integer> itemFreq = new HashMap<>();
for (String s : input) {
@scolton99
scolton99 / opt.js
Created May 25, 2021 23:23
My solution to the word frequency problem in JavaScript.
const input = ["apple", "apple", "orange"];
const itemFreq = {};
for (const s of input) {
if (!(s in itemFreq))
itemFreq[s] = 0;
itemFreq[s]++;
}
@scolton99
scolton99 / tree.js
Created June 28, 2021 19:18
A sketch of way to generate a decision tree on a website.
const selector = "#root > li";
const tree = {
dom_el: null,
text: 'root',
children: []
};
const gen_tree = () => {
const init = Array.from(document.querySelectorAll(selector));
@scolton99
scolton99 / exam_review.c
Created June 29, 2021 23:16
C file used to generate assembly for the first midterm review of NU COMP_SCI 213-0 (Spring 2021).
long sus(long l, long m) {
/* do nothing useful */
if (!m)
return 0;
else
return l + sus(l - 1, m - 1);
}
int amogus(unsigned char z) {
long y = 0;
@scolton99
scolton99 / wait.js
Created September 16, 2021 20:38
Quick and dirty way to make a "sleep"-type function in JS (Browser or Node).
const WAIT_TIME_MS = 3 * 1000;
const wait = async ms => {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
const main = async () => {
await wait(WAIT_TIME_MS);
@scolton99
scolton99 / untab.mjs
Created September 24, 2021 22:55
Convert tabs to spaces while keeping formatting. (Untested on non-4 tab sizes.)
import fs from 'fs/promises';
let TAB_SIZE = 4;
const load_lines = async filename => {
const data = await fs.readFile(filename, { encoding: 'utf-8' });
await fs.writeFile(`${filename}.bak`, data);
return data.split('\n');