Skip to content

Instantly share code, notes, and snippets.

View ryankuykendall's full-sized avatar

Ryan Kuykendall ryankuykendall

  • Seattle, WA
View GitHub Profile
/** This can be replace with Intl.NumberFormatter */
commafy = (num) => {
const [whole, decimal] = num.toString().split('.');
const collection = [];
const places = whole.split('');
while (places.length > 0) {
const three = [];
for (let i = 0 ; i < 3 ; i++) {
if (places.length) {
three.unshift(places.pop());
@ryankuykendall
ryankuykendall / style-property-map-condenser.js
Last active July 13, 2019 05:43
Condenser for StylePropertyMap (element.computedStyleMap())
// WIP: Work in progress!!!
// TODO (ryan):
// 1. Further classify style attributes (HTML vs. SVG vs. Condensible)
// 2. Create dispatch table/handlers for special cases (e.g., column-*, where if column-count == 'auto',
// drop all column styles. Or for attrs like background-image: url(...), go fetch the image and
// inline it as a Data URL.
condenser = (() => {
const Vendor = {
WebKit: 'webkit'
@ryankuykendall
ryankuykendall / collect-node-attributes.js
Last active November 18, 2020 03:42
Helper snippets for working with Element attributes and CSSOM
// Assumes selected node in Chrome Developer tools
[...$0.getAttributeNames()].map((name) => [name, $0.getAttribute(name)]);
module ThreeDTicTacToe
class Game
attr_reader :length_to_win
def initialize(length_to_win = 3)
@ryankuykendall
ryankuykendall / Benchmarking (cont'd from other file)
Created September 11, 2009 18:51
Dual Pivot QSort in Ruby Benchmarked
1.upto(7) do |order_of_magnitude|
quantity_of_items_to_sort = 10 ** order_of_magnitude
items_to_sort = Array.new(quantity_of_items_to_sort) {|index| rand(quantity_of_items_to_sort)}
sorted_with_qsort = nil
time_with_built_in_qsort = Benchmark.realtime do
sorted_with_qsort = items_to_sort.sort
end