Skip to content

Instantly share code, notes, and snippets.

View benslv's full-sized avatar

Ben Silverman benslv

View GitHub Profile
@benslv
benslv / index.html
Created June 10, 2021 13:34
Switch IIFE vs. Object Lookup benchmark (http://jsbench.github.io/#4c30c92c42c1aa7e1400316f3c6e981e) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Switch IIFE vs. Object Lookup benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@benslv
benslv / keybase.md
Created March 20, 2021 11:52
keybase.md

Keybase proof

I hereby claim:

  • I am benslv on github.
  • I am bensilverman (https://keybase.io/bensilverman) on keybase.
  • I have a public key whose fingerprint is B4CF 4405 FFEA F8CB 8F24 598F F70D F5B0 D73F AA2B

To claim this, I am signing this object:

@benslv
benslv / App.js
Created March 3, 2021 14:12
Access current tab URL from a React-based broswer extension
/*global browser*/
import React, { useState } from "react";
import "./App.css";
function App() {
const [currentURL, setCurrentURL] = useState("");
const grabURL = async () => {
const tabs = await browser.tabs.query({
@benslv
benslv / sleepSort.js
Created February 16, 2021 15:38
An O(max(array)) sorting algorithm...
const sleepSort = async (arr) => {
const sorted = [];
const max = Math.max(...arr);
const min = Math.min(...arr);
for (let item of arr) {
setTimeout(() => sorted.push(item), item - min);
}
await new Promise((resolve) => setTimeout(resolve, max));

Keybase proof

I hereby claim:

  • I am silverben10 on github.
  • I am bensilverman (https://keybase.io/bensilverman) on keybase.
  • I have a public key ASAAqgR0uUTgI25nre5dxt5LD4g4rrHe0VY7xZCsCsbkZgo

To claim this, I am signing this object:

@benslv
benslv / pearkdarkblue.yml
Created July 8, 2020 09:34
YAML file for the PearkDarkBlue colour scheme.
# Colors (PearDarkBlue)
colors:
# Default colors
primary:
background: "#222226"
foreground: "#ffffff"
# Normal colors
normal:
black: "#b4b4b4" # Uses grey instead.
@benslv
benslv / fcfs.py
Created May 6, 2020 10:07
Some scheduling algorithms
'''
FCFS Algorithm:
- Take process from front of priority queue.
- Let it execute until process terminates (i.e. for duration of process)
- Pop it from the queue and add to list of completed tasks.
- Repeat until zero processes left.
'''
def fcfs(queue, verbose=False):
completed = []
@benslv
benslv / keybase.md
Created February 16, 2020 14:39
Sorry about that, @Sciencentistguy made me do this.

Keybase proof

I hereby claim:

  • I am silverben10 on github.
  • I am bensilverman (https://keybase.io/bensilverman) on keybase.
  • I have a public key ASD6prf_pW8RxojsOkkUuGgc4WDHvlp5i0lquPDxpSyraQo

To claim this, I am signing this object:

@benslv
benslv / 3. Less Than Ten.py
Created September 7, 2018 10:31
3. Less Than Ten
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
for item in a:
if item < 5:
print(item)
b = []
for item in a:
if item < 5:
b.append(item)
@benslv
benslv / 2. Odd or Even.py
Created September 7, 2018 10:27
2. Odd or Even
inpNumber = int(input("Please enter a number: "))
if inpNumber % 4 == 0:
print("This number is divisible by 4.")
elif inpNumber % 2 == 0:
print("This number is even!")
else:
print("This number is odd.")
num = int(input("Please enter another number: "))