Skip to content

Instantly share code, notes, and snippets.

@bpluly
bpluly / tweepy_dm_example.py
Last active July 22, 2021 15:35
Tweepy Account Activity Getting DMs
# This is a part of a web app that subscribes to all Activity using the Tweepy ActivityAPI module.
# This assumes that the authentication and setup of the application connected to a user has been done.
# In this case the connection is for a single Twitter Account because it's actually a service handling
# everything the backend of zettel.io needs in the way of API and services.
# The webhook gets all of the Account Activity and sends each event onto a queue, there's a filter
# subscribed to the queue which parses the events and cherry picks the ones that are wanted.
# Things that look like dictionaries in this tend to be a database or a document, it's all config related
# in this example.
from tweepy.binder import bind_api
@bpluly
bpluly / orderexample
Last active February 11, 2022 15:46
Couchdb example of using one document to index others, for alternate orders
The order document specifies different orders of the same set of documents.
{
"_id": "order",
"_rev": "11-f5ddfed421c4cfcd24ab38ae74e34723",
"zettelNoteType": "order",
"order": [
{
"orderKey": "bpluly",
"orderList": [
"00000000-150d3af6-8e17-46e5-8da5-4bf7935e52ac",
@bpluly
bpluly / gist:e2585bac2af9c16c59b4cba8f182eeb6
Created May 19, 2022 16:27
Upgrading Couchdb when bintray.apache was the original repo for the installation
In the case where an RPM was originally installed from bintray in fixing you have to modify the baseurl to be the same release version os as the original install.
For el7, explicitly make it el7, do not change it to 8 or vice versa.
Then the update will happen without any intervention.
If you do then you will likely have to install libmozjs.rpm by hand and you will then have a revision conflict with zlib.
Additionally, for speed you can edit the bintray .repo file to have the jfrog baseurl and gpgkey (still specifying el7 or el8). But it's preferable to disable bintray and add the repo https://couchdb.apache.org/repo/couchdb.repo, then edit couchdb.rep as above.
@bpluly
bpluly / gist:36552662084cd5c1ee00a7b6b757e0e4
Created June 8, 2022 10:29
Highlight broken on Ultraedit Linux on Elementary
The File View, and probably other dockable windows doesn't style hightlighted elements properly.
The highlighted line has an opaque fill in which ever GTK system stylesheet is in force.
Only if you click the highlight does the background text appear through the highlight.
The solution I found was to force applications to use the Dark Theme, then restart Ultraedit.
Ultraedit then uses the GTK style sheet for dockable windows properly, even when changing the theme in UE itself.
From Python documentation for 3.8
pprint
The pprint module added a sort_dicts parameter to several functions. By default, those functions continue to sort dictionaries before rendering or printing. However, if sort_dicts is set to false, the dictionaries retain the order that keys were inserted. This can be useful for comparison to JSON inputs during debugging.
In addition, there is a convenience new function, pprint.pp() that is like pprint.pprint() but with sort_dicts defaulting to False:
>>>
>>> from pprint import pprint, pp
@bpluly
bpluly / gist:841d58635306123f40599f2b98b946fe
Created April 18, 2023 11:22
Island Folk Track Listing
Album Artist,Album,Disc#,Track#,Title,Track Artist(s),Composer(s),,Source,Is Dup?,Is Hidden?,Tags
Various Artists,Mojo Presents: Island Folk,1,1,Go Down Easy,John Martyn,John Martyn,,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,2,The Sea,Fotheringay,Sandy Denny,,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,3,We Used to Know,Jethro Tull,Ian Anderson,,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,4,Lonely Boy,Nirvana,"Alex Spyropoulos, Patrick Campbell-Lyons",,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,5,Primrose Hill,John Martyn / Beverley Martyn,John Martyn,,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,6,No More Sad Refrains,Sandy Denny,Sandy Denny,,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,8,Red Hair,The Incredible String Band,Mike Heron,,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,9,Where Are Your Smiles At,Claire Hamill,"Claire Hamill, Mike Coles",,Local,no,no,
Various Artists,Mojo Presents: Island Folk,1,10,She
@bpluly
bpluly / gist:7777c72211bf0002a1ade54a88e31bc3
Last active October 31, 2023 16:20
Using rsync from Fabric2/Patchwork/Paramiko on AWS EIC connections to update certificates on HAProxy

Further adventures in EIC land. I use Fabric2 for all the distribution of code and as much Opswork as I can. That includes updating certs. The certs are all managed from my local machine and then distributed. I use rsync to move the certificate trees (all LetsEncrypt). Before using EIC this was simple the same ssh config could be used but had to be repeated for the Patchwork rsync as it makes its own connection even though there's an existing connection to the host. The ssh_opts for EIC mean you have to inject the InstanceId for each host, the Paramiko Connection object might have it but I failed to find it spelunking; it relies on the ssh_opts parameter to fill the rsync options.

Using the EC2 API DescribeInstances gets the InstanceId along with everything else about the instance and using the Private DNS for the host filters the API response. To get the Private DNS on my ssh config I use the Connection objects which has the updated host string, converting Hostname to the Host which is either an IP address

@bpluly
bpluly / gist:333c3df0e57aeb5318c20f39a8e0093f
Last active October 31, 2023 16:20
Using AWS EIC (EC2 Instance Connect) with OpenSSH

As AWS are going to start charging for all public IPv4 endpoints I have started to look at how to rotate out as manu instances as possible but still have the same mechanisms to access and manage them, ie ssh.

I could leave the Bastion and connect to everything on the private network via the Bastion that's much the samed as now except re-rolling all the instances to remove the public interface. There is EC2 Instance Connect which AWS have just beefed up and is available for AWS Linux 2 and Ubuntu so I tried that.

It has all the convolutions of any other soft networking solution and further commits the sin of requiring aws commands to do the usual work of setting up a tunnel. This is presuming that each connection is a new tunnel from the client to the instance, there's no Bastion so the controls in the Security Group need to be tied down.

Everything seemed mostly ok until I tried to actually connect to an instance, this was with using one of the few examples in the documentation. These examples are all comm

@bpluly
bpluly / gist:7bbbc0520c98c8fcd731b54e9079a2f9
Last active October 31, 2023 16:21
Installing Postgres15 on AWS 2

Whilst AWS Linux 2023 has an up to date package, AWS Linux 2 does not but the former isn't suitable for anything that requires EPEL or much in the way of customising.

sudo rpm -ivh --nodeps https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm sudo sed -i 's/\$releasever/7/g' /etc/yum.repos.d/pgdg-redhat-all.repo sudo yum install -y postgresql15 postgresql15-server PGSETUP_INITDB_OPTIONS='--encoding=UTF-8 --locale=C.UTF-8' sudo /usr/pgsql-15/bin/postgresql-15-setup initdb sudo systemctl enable --now postgresql-15 systemctl status postgresql-15

In creating the graph view in Zettel.io of notes in a kasten I wanted to maintain the general method of not relying upon frameworks. For the Card and Strips view in the Kasten I used Canvas for the linking lines layer between notes. On the graph I wanted to show it as a kind of entity graph, ellipses with links, and later tags, connecting the notes.

I did not want a force graph as in d3 because that's very stiff the user can kind of change the view of the graph but it's hard to place them easily.

The graph page is the same kind of structure as the Card and Strip views but I separated it out as its own template. Within each Node set of DIVs there's an SVG viewBox with an ellipse and a text element inside, the text is just the summary or title of the Note. At the moment that's only 20 characters long.

I thought it would be as simple as the original Drag n Drop to move elements around as it orginally was for Cards and Strips before I refactored it to have ordering on the notes. But (after the travail to unde