Skip to content

Instantly share code, notes, and snippets.

@zelaznik
zelaznik / auto_adjust_table_column_widths.js
Created May 16, 2023 19:05
Javascript Code To Make Sure Table Column Widths Are Consistent
function equalize_widths(table) {
var col_count = [...table.querySelectorAll('thead > tr > th')].length;
var total_table_width = 0;
for (let i=0; i<col_count; i++) {
let elements = [...table.querySelectorAll(`thead > tr > th:nth-child(${i+1}), tbody > tr > td:nth-child(${i+1})`)];
let max_column_width = elements.reduce(function(acc, el) {
let computedStyle = window.getComputedStyle(el);
require 'rspec/expectations'
=begin
# Example use case in a test suite:
# Make sure to have defined a factory in factory-bot for "job_application"
describe JobApplication, type: :model do
it { is_expected.to enforce_uniqueness_of(:uuid) }
end
=end
require 'openssl'
# THIS IS A WORK IN PROGRESS
# NOT READY FOR PRODUCTION
# YOU'VE BEEN WARNED
class PostgresEncryptionSerializer
VALID_DATA_PATTERN = /\\x([0-9a-fA-F]{4})+/
def self.load(binary_encrypted_data)
if binary_encrypted_data.nil?
#!/bin/bash
function find_existing_files() {
# This prevents me from shooting myself in the foot when I'm
# grepping for a pattern and forget to include "-l" before
# using xargs to open the files in sublime
for filepath in $@; do
if [ -f $filepath ]; then
echo $filepath
@zelaznik
zelaznik / active_link_controller.js
Last active May 2, 2022 11:21
Making an "active" link in Rails / Stimulus
from collections.abc import MutableSet
class SingleEntrySet(MutableSet):
"""\
I created this class for debugging. It works like a regular set but it
raises an error if it tries to add an item that is already present.
"""
__slots__ = ("__items",)
class memoized_property:
def __init__(self, method):
self.__method = method
prefix = method.__qualname__.rsplit(".")[0].replace(".", "__")
self.__name = '_%s__%s' % (prefix, method.__name__)
def __get__(self, obj, objtype=None):
if obj is None:
return self
@zelaznik
zelaznik / json_to_csv
Last active October 20, 2021 16:32
Convert JSON to CSV in Python
#!/usr/bin/python3
import csv
import io
import json
import pdb
import sys
from collections import OrderedDict
@zelaznik
zelaznik / emumerable.js
Last active September 20, 2024 19:36
Implement Ruby's Enumerable.Lazy in Javascript
/* This is just a demonstration of how to write an ierator from scratch */
function range(limit) {
var i = 0;
return {
[Symbol.iterator]: function() {
return this;
},
next: function() {
if (i < limit) {
@zelaznik
zelaznik / components.location-picker\.js
Last active April 27, 2020 18:36
Actions And Glimmer Components
import GlimmerComponent from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import EmberComponent from '@ember/component';
import { action } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import { addObserver } from '@ember/object/observers';
function myAction(_target, _name, descriptor) {
const original = descriptor.value;