Skip to content

Instantly share code, notes, and snippets.

@davepeck
davepeck / bad.coffee
Created December 7, 2012 21:39
ES5 properties and coffee script
Function::property = (prop, desc) ->
Object.defineProperty this.prototype, prop, desc
class Foo
@property 'neat'
get: ->
42
class Bar extends Foo
@property 'neat'
@davepeck
davepeck / bq.py
Last active January 5, 2024 17:20
Toying around with a very naive python BigQuery query builder + related utilities
"""BigQuery utilities."""
import datetime
import typing as t
from abc import ABC, abstractmethod
from google.cloud import bigquery
from google.cloud.bigquery import query
type QueryParamValue = str | int | float | datetime.date | datetime.datetime | t.Sequence[ # noqa: E501
@davepeck
davepeck / well-known-redirect.js
Created January 25, 2023 22:04
My first cloudfront edge function
// note that a lot of code choices here are due to the fact that cloudfront edge uses
// a hilariously backwards version of javascript:
//
// "const", you say? what's that?!
// deal with the painful structure that cloudfront edge functions use for query params
function getURLSearchParamsString(obj) {
var str = [];
for (var param in obj) {
if (obj[param].multiValue) {
@davepeck
davepeck / game_of_life_copilot.py
Last active January 24, 2023 17:17
Game of life, python CLI, entirely written by GitHub Copilot (I only wrote the comments!)
import time
from random import random
from typing import Set, Tuple
# Set the default BOARD_SIZE to 40
BOARD_SIZE = 40
def init_board_with_n_gliders(n: int) -> Set[Tuple[int, int]]:
"""Initialize a board with n gliders."""
@davepeck
davepeck / validate-css.mjs
Last active April 24, 2022 20:44
Example of how to run vscode's built-in CSS validations from the command-line. Use `node validate-css.mjs *.css`.
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. */

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 / Today's Wordle Solution.md
Last active January 8, 2022 00:25
Compute today's wordle solution

It's pretty simple. Example usage:

>  python3 wordle.py
banal
@davepeck
davepeck / BinaryDataScanner.h
Created April 27, 2009 04:35
Two simple Objective-C classes that make it crazy easy to read data from sequential binary files.
//
// BinaryDataScanner.m
//
// Copyright 2009 Dave Peck <davepeck [at] davepeck [dot] org>. All rights reserved.
// http://davepeck.org/
//
// This class makes it quite a bit easier to read sequential binary files in Objective-C.
//
// This code is released under the BSD license. If you use it in your product, please
// let me know and, if possible, please put me in your credits.
@davepeck
davepeck / build_libarchive_3_for_ios_8_and_above.md
Last active November 14, 2020 14:38
How to build libarchive 3 (or, really, any autotools-based library) for iOS 8+

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 / using_libarchive.m
Created February 1, 2011 17:20
How to use libarchive to unextract on iOS
/* call processNextArchiveEntry in some kind of loop! */
- (int)processNextArchiveEntry:(struct archive *)archive
{
struct archive_entry *entry = NULL;
int result = ARCHIVE_OK;
result = archive_read_next_header(archive, &entry);
if (result == ARCHIVE_OK)
{