A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label dev. Show all posts
Showing posts with label dev. Show all posts

How to maintain software

You have a massive legacy spaghetti mess of code, and you need to add a new feature.

Write tests first.

Put all your new code in a new module, and only insert single lines into the legacy code to call the new code. This allows you to properly encapsulate the new code, wrap it in try/catch blocks, etc. and not break the legacy system.

Pass whole objects into the new code, this is a necessary consequence of encapsulation.


Note-taking apps for desktop, web and mobile

November 2021

Joplin

Tomboy

  • Tomboy appears very linux-centric, although it has clients for Windows and Mac too.
  • It has an Android app, TomDroid.
  • It has a WebDAV plugin for publishing to the web
  • No web actual app

Evernote

  • Proprietary software
  • Charges actual money
  • Irritating business practices
  • Free version only allows two devices, which isn't enough

Org mode

Colornote

  • Works brilliantly on Android
  • Super fast for short notes
  • No web app

Others

Docker guidance, 2020

DOCKER

Link: https://www.docker.com

Description: Docker download


Link: https://github.com/jesseduffield/lazydocker

Description: Lazy docker - a super cool management of containers (found this weekend)


Link: https://github.com/docker/machine

Description: Docker Machine - easy remote running of docker containers


Link: https://github.com/bcicen/ctop

Description: Like htop but for containers (found this weekend)


Link: https://www.youtube.com/watch?v=3c-iBn73dDE

Description:This women is nothing short of amazing, she does loads of free videos on docker and k8

Level: Advanced


Link: https://www.youtube.com/watch?v=eGz9DS-aIeY

Description: A quick and dirty getting started

level: beginner


Link: https://www.youtube.com/watch?v=IbUXb4pQbPY

Description: a quick overview of docker - Tech lead can be hard to watch at times tbh

level: mid


Link: https://github.com/docker/awesome-compose

Description: A curated list of Docker Compose samples


Link: https://github.com/veggiemonk/awesome-docker

Description: if you are just not a video person


my fav containers (you should check them out):

- mysql

- postgres

- grafana

- Redis

- portainer

- plex

- Rancher

- traefik

- nextcloud

- influxDB

- loki

- cadvisor

- pi-hole

- ubuntu/debian

 

(source: Ash-J B)

Easy/Hard vs Complex/Simple

This may help estimating your stories in agile:

Easy Hard
Simple Washing car Pushing car
Complex Driving car Building car

Ruby debugging gems

A list of debugger add-ons for ruby:
  • debug (old, built-in)
    • ruby -rdebug foo.rb
    • # works
    • # but can't view code around current line automatically like Perl's  {{v
  • pry (no step-through)
    • require 'pry' # at the top
    • binding.pry # in code to define a breakpoint
    • ruby foo.rb
  • pry with step through:
  • pry-byebug (requires ruby >= 2.2.0)

What is DevOps?

I've heard a lot of waffling definitions of DevOps that left me with more questions than answers. A colleague explained it to me like this:

DevOps is where:
  • Developers are responsible for getting code into production, and keeping it running. They receive problem alerts from production.
  • Member of the Operations team attend Development team standups.
  • When a problem arises, the two teams work closely together to resolve it
In contrast, seperate Dev and Ops is:
  • The development team is treated like a third-party supplier, who delivers a fully working and documented application.
  • When the software breaks they are still treated like a third-party supplier

Simple perl webserver

HTTP::Server::Simple

(contrast with python one-liner)

#!/usr/bin/perl

# https://metacpan.org/pod/HTTP::Server::Simple
# /versions/perl-5.8.7/bin/perl -MHTTP::Server::Simple test2.pl

use strict;
use warnings;

{
package MyWebServer;

use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);

my %dispatch = (
    '/hello' => \&resp_hello,
    '/' => \&resp_index,
);

sub handle_request {
    my $self = shift;
    my $cgi  = shift;

    my $path = $cgi->path_info();
    my $handler = $dispatch{$path};

    if (ref($handler) eq "CODE") {
        print "HTTP/1.0 200 OK\r\n";
        $handler->($cgi);

    } else {
        print "HTTP/1.0 404 Not found\r\n";
        print $cgi->header,
              $cgi->start_html('Not found'),
              $cgi->h1('Not found'),
              $cgi->end_html;
    }
}

sub resp_hello {
    my $cgi  = shift;   # CGI.pm object
    return if !ref $cgi;

    my $who = $cgi->param('name');

    print $cgi->header,
          $cgi->start_html("Hello"),
          $cgi->h1("Hello $who!"),
          $cgi->end_html;
}

sub resp_index {
    my $cgi = shift;
    print $cgi->header;
    open(my $fh,'<','index.html') or die "can't open index.html";
    local $/ = undef;
    my $out = <$fh>;
    close($fh);
    print $out;
}

}

# start the server on port 8080
my $pid = MyWebServer->new(8085)->background();
print "Use 'kill $pid' to stop server.\n";

(source)

Git: Change author name in all previous commits

On any branch, or trunk:

git filter-branch --commit-filter 'if [ "$GIT_AUTHOR_NAME" = "Josh Lee" ];
  then export GIT_AUTHOR_NAME="Hobo Bob"; export GIT_AUTHOR_EMAIL=hobo@example.com;
       export GIT_COMMITTER_NAME="Hobo Bob"; export GIT_COMMITTER_EMAIL=hobo@example.com;
fi; git commit-tree "$@"'