Skip to content

Instantly share code, notes, and snippets.

@ipwnponies
ipwnponies / script.fish
Last active September 24, 2022 05:02
House of prime rib reservation
for day_offset in (seq 0 0)
for hour in (seq 16 22)
set open_table_url 'https://www.opentable.com/restref/api/availability?lang=en-US'
set session_token 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJvdGNmcCI6IjQ0MTM2ZmEzNTViMzY3OGExMTQ2YWQxNmY3ZTg2NDllOTRmYjRmYzIxZmU3N2U4MzEwYzA2MGY2MWNhYWZmOGEiLCJpYXQiOjE2NjM4MTAwODAsImV4cCI6MTY2MzgyMDg4MH0.boXS_p4VyIuAGinPb3-DCwBmUIazcckOQnm4itzgAQw'
set house_prime_rib_id 1779
set timestamp ( date -d"2022-11-30 +$day_offset days +$hour hour")
curl $open_table_url -s -X POST -H 'Content-Type: application/json' -H $session_token --data-raw (printf '{"rid":%s,"dateTime":"%s","partySize":2,"enableFutureAvailability":true,"transformOutdoorToDefault":false}' $house_prime_rib_id $timestamp) | \
jq --color-output --sort-keys '.availability |to_entries[] | [.key, .value.timeSlots]'
end
end
@ipwnponies
ipwnponies / sound-ouput-switcher.scpt
Created January 16, 2021 00:04
Switch sound source on OSX
(*
Applescript to toggle to laptop speakers.
Based on code by tetsujin: https://apple.stackexchange.com/a/218223
This is more dynamic, as ordering of items is not guaranteed. Sources exist temporarily,
such as bluetooth headsets or headphone jack.
Motivation:
This script use case is to toggle between the built-in speakers (always exist) and the intended headset.
I'd toggle this to temporarily switch to laptop speakers for presentation or to step away from computer
but want to continue to receive sound notifications.
@ipwnponies
ipwnponies / README.md
Last active September 27, 2020 23:18
Speed test scraper

Usage

  1. Load up the respective websites.
  2. Run script in console.
  3. Click button to run test.
  4. Results will be printed out to the console.

Blog post

@ipwnponies
ipwnponies / Profiling slow nvim startup.md
Last active January 13, 2019 11:04
How to profile slow vim startup

Introduction

Neovim was taking a long time to start up but only on my laptop. Like 2 seconds long. This didn't happen on a shared aws dev box, which led me to thinking this was maybe hardware or OS filesystem caching issue. Here's what I did to debug and get to the bottom of the mystery.

Profiling vim

The first step was to sanity check how slow this was.

@ipwnponies
ipwnponies / es_search.md
Last active May 9, 2018 18:41
Aggregation queries in elasticsearch

A common analysis is counting values, grouped on common attribute. e.g. What are the counts of passing, failing, missing tests.

IN SQL, we can do this:

SELECT name, status, COUNT(*) 
FROM tests 
WHERE date > NOW() - INTERVAL 30 DAY
AND name IN ('test1', 'test2')
GROUP BY name, status
@ipwnponies
ipwnponies / _Fizzbuzz in different languages.md
Last active January 9, 2019 18:55
Fizzbuzz in different languages

What is this

Fizzbuzz in different languages

Why does this even exist

Someone once declined to write fizzbuzz because they had recently only been doing shell programming. And, therefore, my request was invalid and unfair since it's not a real language.

So, for funsies, I'm going to demonstrate that you can write fizzbuzz in turing complete languages. Not an incredible feat, more of a refutation of said argument.

@ipwnponies
ipwnponies / asyncio.md
Last active March 6, 2024 21:35
concurrent.futures (threading) vs. asyncio (event loop)

Summary

This gist demonstrates the difference between threading and asyncio. To be clear, they're both limited by the Global Interpreter Lock and are both single process, multi-threaded. They are both forms of concurrency but not parallelism.

Threading, via concurrent.futures

Threading (via Thread, concurrent.futures) employs time-slicing of CPU. All threads are given a slot of CPU time to do work. If the thread is blocking (sleeping or blocked on sockets), then off it goes to the next thread. With many threads that are blocked for long periods, this begins to degrade into polling (polling vs. interrupt)

@ipwnponies
ipwnponies / gist:0d00f5d6ce1ee335fafc339a7fc3dca6
Last active December 11, 2018 17:02
Add label to gif using imagemagick

Summary

Imagemagick is hard to use and the documentation/tutorials available are not intuitive. Here is a concise explanation of what needs to be done to edit a gif to add labels.

Code

convert foo.gif \                                                            # Specify the original gif
-gravity center -pointsize 30 -font ComicSans \                              # Set font position and styling
-duplicate 1,0-20 \                                                          # Clone frames and append to the end (clone frame once)
'(' -clone 21-40 -fill white -annotate -0-150 'Hello' -set delay 6 ')' \     # Clone frames, add 'Hello', and slow down gif delay for only these frames
-duplicate 1,41-89 \                                                         # Clone frames and append to the end (clone frame once)