Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home (forever)

Dave Peck davepeck

🏠
Working from home (forever)
View GitHub Profile
@davepeck
davepeck / validate-css.mjs
Last active Apr 24, 2022
Example of how to run vscode's built-in CSS validations from the command-line. Use `node validate-css.mjs *.css`.
View validate-css.mjs
import fs from "fs";
import url from "url";
import { getCSSLanguageService } from "vscode-css-languageservice";
import { TextDocument } from "vscode-languageserver-textdocument";
/** Human-readable names for the potential diagnostic severities returned. */
const severities = { 1: "ERR", 2: "WARN", 3: "INFO", 4: "HINT" };
/** Format a position in a given file. */
@davepeck
davepeck / Today's Wordle Solution.md
Last active Jan 8, 2022
Compute today's wordle solution
View Today's Wordle Solution.md

It's pretty simple. Example usage:

>  python3 wordle.py
banal
@davepeck
davepeck / eject_all.scpt
Created Oct 7, 2018
Command line tool to eject all ejectable volumes
View eject_all.scpt
tell application "Finder" to eject (every disk whose ejectable is true and local volume is true and free space is not equal to 0)
@davepeck
davepeck / CertificateSigningRequest.h
Last active May 8, 2020
Objective-C code to generate a CSR via OpenSSL
View CertificateSigningRequest.h
//
// CertificateSigningRequest.h
// Cloak
//
// Created by Dave Peck on 10/31/16.
// Copyright © 2016 Bourgeois Bits LLC. All rights reserved.
// Licensed under the MIT license
//
#import <Foundation/Foundation.h>
View group_reassignment.md

I got hit by the weird group reassignment when I upgraded to Mavericks. In my case the group was macports (!). I’ve seen one report from a user who got cloakproxy after the 10.11 upgrade, so apparently the bug is still there.

For some reason the OS X upgrader sometimes picks a group and changes the PrimaryGroupID to 20. Here’s the confirm:

dscl . -read Groups/cloakproxy
dscl . -read Groups/staff

And the fix:

@davepeck
davepeck / build_libarchive_3_for_ios_8_and_above.md
Last active Nov 14, 2020
How to build libarchive 3 (or, really, any autotools-based library) for iOS 8+
View build_libarchive_3_for_ios_8_and_above.md

How to build libarchive 3 (and, really, any autotools based library) for iOS 8+

It's easy:

  1. Grab iOS-autotools by @szanni from https://github.com/szanni/ios-autotools
  2. Grab libarchive 3 from http://www.libarchive.org/
  3. cd into the libarchive code directory
  4. export ARCHS="armv7 armv7s arm64" (or suitable for your needs and your shell of choice)
  5. Run autoframework ArchiveLib libarchive.a and wait for everything to build!
@davepeck
davepeck / lev.coffee
Last active Aug 29, 2015
Levenshtein Distance in coffeescript
View lev.coffee
# Levenshtein distance with the ability to reward or punish
# longer contiguous matching runs (set contiguousBonus < 1.0 for rewards)
stringDistance = (s, t, deleteCost=1, insertCost=1, substitutionCost=1, contiguousBonus=1.0) ->
sLength = s.length
tLength = t.length
d = []
for i in [0..sLength]
d[i] = [{score: i, contiguous: 0}]
@davepeck
davepeck / interleave.py
Last active Aug 29, 2015
Random python iteration toy
View interleave.py
def interleave(iterables, cmp=None, key=None, reverse=False):
"""
Given a collection of iterables, walk through them in
parallel, at each step yielding the current value
that comes first in the sort order, and advancing
that single iterator.
If each iterable is already sorted, this will produce
a total ordering. If not, it produces a 'greedy' ordering
View BinaryDataScanner.swift
//
// BinaryDataScanner.swift
//
// Created by Dave Peck on 7/20/14.
// Copyright (c) 2014 Dave Peck. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
@davepeck
davepeck / alien_example.txt
Last active Aug 29, 2015
Convert black-and-white sprites into... morse code?
View alien_example.txt
Alien in base 16: 183C7EDBFF245AA5
Alien in base 32: 1GF3URFVI8ML5
Alien in base 36: D9NURFZQYYSL
Alien in morse, base 16: ['.----', '---..', '...--', '-.-.', '--...', '.', '-..', '-...', '..-.', '..-.', '..---', '....-', '.....', '.-', '.-', '.....']
Alien in morse, base 32: ['.----', '--.', '..-.', '...--', '..-', '.-.', '..-.', '...-', '..', '---..', '--', '.-..', '.....']
Alien in morse, base 36: ['-..', '----.', '-.', '..-', '.-.', '..-.', '--..', '--.-', '-.--', '-.--', '...', '.-..']