Skip to content

Instantly share code, notes, and snippets.

View elliotlarson's full-sized avatar

Elliot Larson elliotlarson

View GitHub Profile
@elliotlarson
elliotlarson / immutable-operations.spec.js
Last active February 10, 2024 07:08
JavaScript Immutable Operations on Arrays and Objects
// This is a Jest spec that explores some of the different ways to alter
// arrays and objects without mutating state. I'm trying different approaches
// available using:
//
// * Vanilla JS
// * Immutable.js
// * Lodash
// * Rambda
//
// The motivation for this is largely to work with a Redux store.
@elliotlarson
elliotlarson / ibeacon-scan.bash
Last active March 2, 2023 02:07
iBeacon Scanning Bash Script
#!/bin/bash
# iBeacon Scanner
# refactored script from Radius Networks referenced in this StackOverflow answer:
# http://stackoverflow.com/questions/21733228/can-raspberrypi-with-ble-dongle-detect-ibeacons?lq=1
# Process:
# 1. start hcitool lescan
# 2. begin reading from hcidump
# 3. packets span multiple lines from dump, so assemble packets from multiline stdin
# 4. for each packet, process into uuid, major, minor, power, and RSSI
@elliotlarson
elliotlarson / favicon-creator.sh
Created January 8, 2017 20:34
Create favicon from PNG
convert my-image.png -define icon:auto-resize=128,64,48,32,16 favicon.ico
@elliotlarson
elliotlarson / firebase.admin.repl.js
Last active April 21, 2021 13:44
Simple Node.js Firebase repl
#!/usr/bin/env node
// Using the firebase-admin approach where database security rules do not apply.
// Here you are authenticating with a private key. The key JSON file is available via
// the Firebase web UI: project settings > service accounts > generate new private key.
var admin = require("firebase-admin");
admin.initializeApp({
credential: admin.credential.cert(".adminServiceAccountKey.json"),
const newCharacters = Object.assign(characters, { [maude.id]: maude });
require 'test_helper'
class FoosControllerTest < ActionDispatch::IntegrationTest
setup do
@foo = foos(:one)
end
test "should get index" do
get foos_url
assert_response :success
// You don't need to type cast the integer `deleteId` to a string in the
// browser, but when running Jest specs, I found that I had to cast to a
// string. Maybe this is a difference between browser JS and Node, which
// the tests run in?
const { [`${deleteId}`]: deleted, ...newCharacters } = characters;
@elliotlarson
elliotlarson / color-go-test.bash
Last active August 3, 2018 23:11
Colorizing Golang Test Output
#!/bin/bash
# Colorizing Go test output:
# This is meant to be used in place of `go test`. Provided this script is in
# your PATH, calling `color-go-test` will call through to `go test` and then
# colorize and reformat the output.
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
const newCharacters = [...characters, "Maude"];
stateChanges.push(newCharacters);
// stateChanges:
// [
// ["Walter", "Jeffrey", "Donald"],
// ["Walter", "Jeffrey", "Donald", "Maude"],
// ]
characters.push("Maude");
stateChanges.push(characters);
// stateChanges:
// [
// ["Walter", "Jeffrey", "Donald", "Maude"],
// ["Walter", "Jeffrey", "Donald", "Maude"],
// ]