Skip to content

Instantly share code, notes, and snippets.

@olih
olih / jq-cheetsheet.md
Last active March 19, 2025 21:07
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

# config/initializers/phlex_template_handler.rb
require "action_view"
require "phlex"
# Intercept unknown "capitalized" method calls (e.g., PageView(...)) in templates,
# look up a Phlex component class, instantiate it, and render it.
# Crucially, we re-bind the user’s block so that `self` is the component, not the ActionView context.
module PhlexDynamicMethodCalls
def method_missing(name, *args, **kwargs, &block)
# Only intercept method calls starting with an uppercase letter (e.g. "PageView", "MyComponent", etc.)
@davesteele
davesteele / cache_dict.py
Last active March 19, 2025 21:05
Python LRU Caching Dictionary - a dict with a limited number of entries, removing LRU elements as necessary
from collections import OrderedDict
# >>> import cache_dict
# >>> c = cache_dict.CacheDict(cache_len=2)
# >>> c[1] = 1
# >>> c[2] = 2
# >>> c[3] = 3
# >>> c
# CacheDict([(2, 2), (3, 3)])
# >>> c[2]
rubocop -a `git diff --name-only --cached | grep '\.rb'`
@mcrumm
mcrumm / phx_sqlite_fly_launch.md
Last active March 19, 2025 21:03
Phoenix + SQLite Deployment tips

Deploying to Fly.io with SQLite

Deploying a Phoenix app to Fly.io is a breeze...is what everyone kept telling me. In fairness, I imagine the process would have been breezier had I just used postgres, but all the sqlite and litestream talk has been far too intriguing to ignore. "Wait", you say. "It is just a flat file. How much harder can it be?"

It is easy to make something harder than it should be. It is hard to take something complex and make it truly simple. flyctl launch does an amazing job at providing a simple interface to the utterly complex task of generating deployment resources, especially now that we are living in a containerd (erm, firecracker) world.

This gist is for anyone who, like me, thinks they know better than to read all of the documentation and therefore necessari

TMUX - Single window group, multiple session.

So I have been using tmux for a while and have grown to like it and have since added many many customizations to it. Now once you start getting the hang of it, you'll naturally want to do more with the tool.

Now tmux has a concept of window-group and session and if you are like me you'll want multiple session that connects to the same window group instead of a new window group every time. Basically I just need different views into the same set of windows that I have already created, I don't want to create a new set of windows every time I fire up my terminal.

This is the default case if you simply use the tmux command as your login shell, effectively creating a new group of windows every time you start tmux.

This is less than ideal because, if you are like me, you fire up one-off terminals all the time and you don't want all those one-off jobs to stay running in the background. Plus sometimes you need information fro

@jlpouffier
jlpouffier / voice_preview_edition_experimental_streaming_wake_word_firmware.yaml
Created December 16, 2024 20:45
Voice Preview Edition Experimental Streaming Wake Word Firmware
substitutions:
# Phases of the Voice Assistant
# The voice assistant is ready to be triggered by a wake word
voice_assist_idle_phase_id: '1'
# The voice assistant is waiting for a voice command (after being triggered by the wake word)
voice_assist_waiting_for_command_phase_id: '2'
# The voice assistant is listening for a voice command
voice_assist_listening_for_command_phase_id: '3'
# The voice assistant is currently processing the command
voice_assist_thinking_phase_id: '4'
@joxz
joxz / windows_ts.md
Last active March 19, 2025 20:57
Windows Troubleshooting

Windows WLAN Trace

netsh wlan set tracing mode=yes
netsh wlan set tracing mode=no

Once a trace has been completed, a report is compiled at C:\windows\tracing\wireless and viewable in the Windows performance monitor.

ETW network traces

@disler
disler / README.md
Last active March 19, 2025 20:53
Four Level Framework for Prompt Engineering
@coolzjy
coolzjy / change-zhihu-user-agent.js
Last active March 19, 2025 20:51
Shadowrocket Scripts
(function () {
const headers = $response.headers;
for (let key in headers) {
if (key.toUpperCase() === 'CONTENT-TYPE' && !headers[key].includes('text/html')) {
$done({});
return;
}
if (key.toUpperCase() === 'CONTENT-SECURITY-POLICY') {
delete headers[key];