Skip to content

Instantly share code, notes, and snippets.

View chipbell4's full-sized avatar
👊
KAMPUTORS!

Chip Bell chipbell4

👊
KAMPUTORS!
View GitHub Profile
@chipbell4
chipbell4 / checkbox-list.js
Created February 27, 2021 17:47
A custom element for rendering a checkbox list
/**
* A custom element for rendering a checkbox list of items. Example:
* <checkbox-list
* title="Hello World"
* itemLabels="Apple,Banana, Chocolate"
* items="a,b,c"
* value="all"
* />
*
* And change can be detected with:
@chipbell4
chipbell4 / triangle.py
Created April 14, 2018 01:54
Triangle Wave Generation
import numpy as np
import scipy.io.wavfile
# generate a "canonical" waveform
elements = []
for i in range(0, 255):
for k in range(20):
elements.append(i)
for i in range(255, 0, -1):
for k in range(20):
@chipbell4
chipbell4 / kmp.py
Created September 19, 2017 12:44
A Knuth-Morris-Pratt Algorithm example
def build_table(W):
# initialize our table
T = [-1 for element in W]
# the current position we're calculating a table value
pos = 1
# an extra index for referencing the candidate location that a mismatch would start over at.
cnd = 0
@chipbell4
chipbell4 / webgl.js
Created September 1, 2016 20:37
A bare-bones WebGL starter template, that renders vertices with shaders. Also shows an example uniform usage. Auto-injects on the page if possible.
(function() {
// Get a context
var canvas = document.createElement('canvas');
var gl = null;
try {
gl = canvas.getContext('webgl');
if(!gl) throw new Error('');
} catch(e) {
return false;
}
@chipbell4
chipbell4 / dnd.js
Last active July 26, 2016 18:24
Simple Drag and Drop
function makeDraggable(element, onDragMove, onDragEnd) {
element.style.position = 'absolute';
var mouseIsDown = false;
var offset = { x: 0, y: 0};
var oldZIndex = '';
element.addEventListener('mousedown', function(evt) {
oldZIndex = element.style.zIndex;
element.style.zIndex = 999;
@chipbell4
chipbell4 / simplicity.py
Created May 5, 2016 00:59
Solution for ACM SER 2016 Division 2 "Simplicity"
# A class for holding the unique letters from a string, and their number of occurences
class LetterSet:
# constructor, adds the words to a dictionary with letters as keys and letter counts as values
# ala: { 'a': 4, 'b' : 2, ... } etc.
def __init__(self, word):
self.letter_counts = {}
for letter in word:
self.add_letter(letter)
@chipbell4
chipbell4 / clr.js
Created January 16, 2016 05:11
CLR Simulation (Interesting results...)
var _ = require('lodash');
var chiSquaredTest = require('chi-squared-test');
var seedrandom = require('seedrandom');
var rng = seedrandom('hello.');
function rollDie(sides) {
var index = Math.floor(rng() * sides.length);
return sides[index];
}
@chipbell4
chipbell4 / generateData.py
Created November 8, 2015 02:51
Problem 3 "Planet Mining" Solution
from random import uniform
numberOfCases = 1000
print(numberOfCases + 1)
# an edge case to test for
print('0.1 0.1 1 1')
for i in range(numberOfCases):
starting_concentration = uniform(0.25, 0.5)
@chipbell4
chipbell4 / welding.py
Created November 8, 2015 02:49
The Problem 2 "Welding" Solution from CCSCSE Small College Programming Contest
from math import cos, sin, pi
def distance(p1, p2):
dx = p1[0] - p2[0]
dy = p1[1] - p2[1]
return (dx * dx + dy * dy)**0.5
def equals(p1, p2, epsilon=0.001):
return distance(p1, p2) <= epsilon
@chipbell4
chipbell4 / teaser.html
Created October 23, 2015 17:31
A Flexbox version for having a slider with text
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
.container {
height: 10em;
margin: 0;