karzilla: a green fist above the word SMASH! (Default)
2022-11-11 09:54 am
Entry tags:

reverting a commit in git

In case anyone else finds this useful (and so I can easily look it up again later):

If you've already deployed a commit that you need to revert, you can get the changes you need in two quick steps:

1. git log -1 -p [sha] > [txtfile]

2. git apply --reverse [txtfile]

Then add and commit as normal.

In my case, I needed to back out two commits. Just make sure you apply the reversion for the newer commit first.




Also, hi! Since my last post here about Docker, I eventually wandered away from my attempts to get a Dreamwidth development container suite working. A DW install has a lot of moving parts that need to be able to communicate with each other, so my efforts to keep all the various services properly separated in their own individual containers quickly grew unwieldy. I might come back to that project at a later date, but for now I'm using a cloud provider to run my own development system on dw.kareila.net.
karzilla: a green fist above the word SMASH! (Default)
2022-01-29 07:42 pm
Entry tags:

learning about Docker

I've been meaning to teach myself about Docker since at least June of 2020, the last time I attended a technical conference (albeit online) and noticed that it was a common point of reference. Also, Dreamwidth has been using Docker in production since around that time. But I didn't manage to clear up the mental bandwidth to study it until this past week. I'm going to share my notes here, since I think it's a helpful thing to know about.

What is Docker? It's a software package that provides an isolated system environment for running applications. In practice, a Docker instance is not unlike a virtual machine, but with one key difference: you don't have to install and maintain a separate operating system. A Docker image is relatively lightweight and completely portable across different systems. Bonus: it doesn't cost anything to use unless you're a large company.

I found these resources particularly helpful:

1. Video: Learn Docker in 12 Minutes and its sequel, Docker Compose in 12 Minutes. I found these two to be the most accurate and accessible of the ones I viewed. There are many other similar videos online if you find those to be a bit too fast-paced, but the presentation quality varies widely.

2. Reading: The Docker Handbook is a free online book, presented as a single really long web page, that does an excellent job of describing how to use Docker.

3. Tutorial: Upon installing Docker, the software will instruct you to run its "getting-started" image, which contains some basic lessons and exercises. You can also view the same material on the Docker website.

All three of those explain how to get Docker on your machine, so I won't go into that here. Instead, here's a data dump from the notes I took when I was clarifying the basic concepts in my head.

Read more... )

I've only done the tutorial so far; my next goal, obviously, is to figure out how to use Docker to run a local DW development environment. The files in https://github.com/dreamwidth/dw-free/tree/master/etc/docker should provide a good starting point.
karzilla: a green fist above the word SMASH! (Default)
2013-06-06 05:35 pm
Entry tags:

Upgrading your Perl scripts to use the Twitter 1.1 API

AS ORIGINALLY WRITTEN THIS DOES NOT WORK WITH THE CURRENT API. SEE UPDATES BELOW.

If you follow [twitter.com profile] kareila you have already seen this, but there's a [twitter.com profile] dw_alerts account that posts errors from Dreamwidth's Nagios log, and it was broken until I fixed it a couple of days ago. It wasn't hard. Here's what I did:

Request API keys from Twitter

1] Go to https://dev.twitter.com/apps and sign in with the account you are using with your script (in my case, dw_alerts).

2] Click "Create a new application".

3] Give your application a name - I used "DW Nagios Gateway" - and a description (in my case, also "DW Nagios Gateway"). The only other required field is website - use whatever you feel is appropriate here. Leave "Callback URL" blank, agree to the terms, prove your sentience, and submit the form.

4] Now you should be on the Details page for your new application. Before you do anything else, click the Settings tab and scroll down to the choices for "Application Type." Change the selection from "Read only" to "Read and Write," because you want your script to post messages.

5] Go back to the Details tab and click the button to create access tokens.

6] Now from the OAuth tab, you should be able to copy the four keys you need. In your Perl script, it would look something like this:

my %oauth_info = (
    consumer_key => 'aaaa',
    consumer_secret => 'bbbb',
    access_token => 'cccc',
    access_token_secret => 'dddd',
);

(Those values should be long gibberish looking strings, which I am simplifying here.)

This is what you use instead of a username and password to authenticate using the new API.

Update your code to use the new API

Your mileage may vary, but for my purposes, I was able to use Net::Twitter::Lite instead of the more full-featured Net::Twitter. You also need to install and explicitly use Net::OAuth and Mozilla::CA.

use Net::Twitter::Lite;
use Net::OAuth;
use Mozilla::CA;

Here are the three lines of code I use to post $msg to Twitter:

my $tw = Net::Twitter::Lite->new( %oauth_info, ssl => 1 ) or die;
eval { $tw->update( $msg ) };
warn "Twitter error: $@\n" if $@;

That's it! Let me know if you have any problems.

UPDATE: This broke again a week later, when Twitter completely turned off the 1.0 API. But again, CPAN comes to the rescue and the fix is easy: instead of Net::Twitter::Lite, use Net::Twitter::Lite::WithAPIv1_1. Everything else still works as before.

UPDATE 1/2014: Twitter now requires SSL, so I've added "ssl => 1" and "use Mozilla::CA" to the code above to reflect this.