Skip to content

Instantly share code, notes, and snippets.

@onecrayon
onecrayon / Makefile
Last active February 4, 2024 12:30
Load dotenv files into Make environment
# This is an example Makefile stub that demonstrates how to load variables from a dotenv file into
# your Make environment. Note that it isn't perfect; for instance, the double-quoted JSON string
# in the example file will probably not parse correctly because the escape characters will remain
# as part of the string when it is passed through Make, non-JSON multiline strings will cause the
# file to fail to parse with an obscure Make error, and some advanced features such as interpolation
# are not supported.
# I always start my Makefiles with this command, because then they're effectively self-documenting
help: cmd-exists-grep cmd-exists-sed
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v @grep | sed -e 's/\\$$//' | sed -e 's/: [a-zA-Z0-9_][ a-zA-Z0-9_-]*[a-zA-Z0-9]\([[:space:]]*\)##/:\1##/' | sed -e 's/## //' -e 's/##//'
@onecrayon
onecrayon / base-emoji
Created January 29, 2024 23:06
BaseEmoji CLI
#!/usr/bin/env python3
"""BaseEmoji CLI
Inspired by this lovely little gem: https://github.com/amoallim15/base-emoji
But using something a little closer to the base64 algorithm (effectively base128, using emojis).
Comparison of a 13 character/13 byte string in two encodings:
$ base-64 <<< 'Hello, world!'
@onecrayon
onecrayon / queued_processor.py
Created April 5, 2022 21:07
QueuedProcessor
import signal
import sys
from queue import Empty, Queue
from threading import Lock, Thread
from time import sleep
from typing import Callable
class QueuedProcessor:
"""Context manager class for processing script actions in threads
@onecrayon
onecrayon / ContentPostPage.vue
Last active May 31, 2021 21:18
Pages with next/prev links in Gridsome 0.6.x
<template>
<layout>
<!-- Here there be markup... -->
</layout>
</template>
<page-query>
query Chapter ($id: String, $prevId: String, $nextId: String) {
post: contentPost (id: $id) {
title,
@onecrayon
onecrayon / Pipfile
Last active July 25, 2021 09:32
async/await FastAPI with SQLAlchemy test
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
pylint = "*"
[packages]
sqlalchemy = "*"
@onecrayon
onecrayon / README.md
Last active March 20, 2024 08:16
Use git installed in Windows Subsystem for Linux in Visual Studio Code

Proxy commands from Windows command line to Bash using the Windows Subsystem for Linux (WSL)

These scripts allow you to proxy commands (specifically git, in this example) to the Windows Subsystem for Linux from the normal Windows command line environment. This allows you to work with a single installation of git (under your Linux distribution) instead of trying to manage two concurrent installations.

I explicitly created these scripts to allow using Git in Visual Studio Code without installing it under Windows.

Please note that I have not extensively tested edge cases! If you run into problems, please let me know!

Using WSL git in Visual Studio Code

/**
* Automatically populates Zendesk public-facing "new ticket" fields
* on page load.
*
* To use, copy and paste into your New Request Page template (wrapped
* in a `<script></script>` tag).
*
* For most fields, just use the field name (so if the field is
* `request[subject]`, use `subject` in the URL, while
* `request[custom_fields][123456]` becomes `123456`). You can also use
@onecrayon
onecrayon / example_models.py
Created December 13, 2016 20:05
Custom MappedCollection example for SQLAlchemy returning a dict of lists
from sqlalchemy import Model, Column, Integer, ForeignKey, String, Text
from orm_helpers import KeyedListCollection
class ItemAttribute(Model):
__tablename__ = 'item_attributes'
id = Column(Integer, primary_key=True, autoincrement=True)
item_id = Column(Integer, ForeignKey('items.id'))
attribute = Column(String(255))
value = Column(Text)
@onecrayon
onecrayon / dropbox-git-init.sh
Created October 4, 2016 21:08
Bash script for automatically creating a bare git repo in Dropbox (for tracking pre-existing private repo)
##
# This script adds a new git repo to Dropbox (named after the current working
# directory), adds it as a remote, and pushes everything to it. If there is an
# argument, then that will be used as the name of the repo instead of the
# current working directory.
#
# EXAMPLE USAGE:
#
# $ cd existing-repo
# $ /path/to/dropbox-git-init.sh
/**
* flattenArray(nestedArray)
*
* Accepts an array of values and arrays and returns
* a single array of values.
*
* Usage:
*
* var nested = [[1, 2, [3]], 4];
* var flat = flattenArray(nested);