Block google search page ads

April 20, 2018 — jed

While searching for a new anonymous VPN service, I got this search page with the top-half full of ads with no valid search results.

I already have Adblock plus on Firefox. It's just a matter of tweaking the settings to make it more aggressive than its default. Go into Adblock plus options and uncheck "Allow Acceptable Ads".

Reload the search page and observe your stress levels go down.

Tags: google-ads, adblock-plus, firefox

Debian Windows Subsystem for Linux

April 12, 2018 — Jed Mallen

Upgraded to the Fall Creators Update of Windows 10 so I can use WSL.

Found Debian as one of the offerings and installed it.

There was a helpful review there which advised:

apt update
apt full-upgrade
apt install aptitude
aptitude install ~pstandard ~prequired ~pimportant -F%

Installed basic tools (python, tmux, perl, gnupg..) and here it is:

Tags: debian, wsl, windows-subsystem-for-linux, windows10

cygwin/mintty crashes on startup

April 12, 2018 — Jed Mallen

If you're getting this issue, check first if it's not being caused by a bad .minttyrc file (rename it and launch cygwin again).

If it's not the above, check if there are running cygwin processes in the background and just kill them.

Tags: cygwin, mintty.exe

Get AWS ECS target group instance IPs using Python

April 05, 2018 — Jed Mallen

Some routine job we do at work requires a recycle of instances which will be replaced by ASG.

Imagine logging on to your AWS console, going to ECS, then services then tasks, then each task has its list of several instances that you need to ssh to and stop the service. Multiply that by several clusters and you got your hands full. And you have to do this inside a short time.

Because I'm lazy I will script this. Run the script below and you get a list of all the instance IPs under each target-group. That script can also ssh automatically but nah. Maybe some other time for that.

import boto3
import pprint

cluster = "your-webapp-ecs-cluster"
targetgroup1 = "arn:aws:elasticloadbalancing:us-east-1:666666666666:targetgroup/tg1/0f3864e3bf78aaa5"
targetgroup2 = "arn:aws:elasticloadbalancing:us-east-1:666666666666:targetgroup/tg2/4ea77bce7c612c33"
targetgroup3 = "arn:aws:elasticloadbalancing:us-east-1:666666666666:targetgroup/tg3/0f3864e3bf78aaa5"
targetgroup4 = "arn:aws:elasticloadbalancing:us-east-1:666666666666:targetgroup/tg4/db4f648a0ebb7d8a"
targetgroup5 = "arn:aws:elasticloadbalancing:us-east-1:666666666666:targetgroup/tg5/a3d7aaade00c1967"
tgs = [ targetgroup1, targetgroup2, targetgroup3, targetgroup4, targetgroup5 ]

session = boto3.Session(profile_name='your_aws_profile')
ec2_client = session.client('ec2',region_name='us-east-1')
elbv2_client = session.client('elbv2',region_name="us-east-1")
pp = pprint.PrettyPrinter()

for tg in tgs:
    target_group_health = elbv2_client.describe_target_health(TargetGroupArn = tg)
    tg_name = tg.split('/')
    target_len = len(target_group_health['TargetHealthDescriptions'])
    for i in range(0, target_len):
        instance_id = target_group_health['TargetHealthDescriptions'][i]['Target']['Id']
        instance_info = ec2_client.describe_instances(InstanceIds=[instance_id])
        instance_ip = instance_info['Reservations'][0]['Instances'][0]['PrivateIpAddress']
        instance_port = target_group_health['TargetHealthDescriptions'][i]['Target']['Port']
        print(tg_name[1], instance_id, instance_ip)

Tags: python3, boto3, aws-cli, elastic-container-service

Run bash script on specific time without using cron

April 05, 2018 — Jed Mallen

Everybody knows cron is the go to guy for scheduled jobs in unix. But there are some schedules that don't lend itself to cron beautifully.

As an example, at work I have a healthcheck script running to check if our webapp is running and if not start it. Simple.

The issue comes every Tuesday at 3:30 AM to 5:30 AM we have a maintenance window scheduled. During that time all services will be stopped. So if healthcheck is running it will interfere with that and start it back up. We can simply edit the cronjob right? Sure. Try doing that to several servers. It gets pretty tiring to crontab -e, put a comment on that line for healthcheck, save it. Then exit, ssh to the next server, and the next, and the next. You get the idea.

Also, because the schedule is not 3 to 5, it's 3:30 to 5:30, I need to break the cronjob in 4 lines:

Note: the schedule below is in UTC, the one I described above is EST/EDT

* * * * sun,mon,wed,thu,fri,sat
* 0-6,10-23 * * tue
0-29 7 * * tue
31-59 9 * * tue

Fugly right?

And another thing, because the primary schedule we are referenced to is Eastern Standard Time, I need to change the cronjob schedule when DST flips.

So we come to the meat of this post. Below is a way we can reference another timezone and set the schedule when it will run or not. So essentially the cronjob is reduced to this:

* * * * *

And the healthcheck script will have this as it's main function:

mwday=2 # 2 is Tuesday in %u
currentday=`TZ=America/New_York date +%u`
currentdatetime=`TZ=America/New_York date`
if [ "$currentday" -eq "$mwday" ];then
        currenttime=`TZ=America/New_York date +%H%M`
        if [ "$currenttime" -ge "$mwstart" ] && [ "$currenttime" -le "$mwend" ];then
                date >> $log
                echo "MW detected. We are between $mwstart and $mwend. No healthchecks." >> $log
                echo "$currentdatetime"  >> $log
                exit # exit healthcheck as we are on Maintenance Window
                date >> $log
                echo "It's Tuesday BUT we are NOT between $mwstart and $mwend so run healtcheck.">> $log
                echo "$currentdatetime" >> $log
        # it's not Tuesday. run healthcheck.
        date >> $log
        echo "It's not Tuesday. Running healthcheck." >> $log
        TZ=America/New_York date >> $log

Tags: bash, cron, datetime

Extract email addresses between angle brackets using sed

May 09, 2017 — Jed Mallen

If you have a list of email addresses from outlook with proper names and emails in angle brackets (<>) then you can pipe that file into this script and come out with a long line of emails separated by a comma.

# Usage: cat emaillist.txt |
# emaillist.txt contains something similar to the one below:
# John Doe <>; Jane Doe <>; hax0r <>


sed 's/; /\n/g' $emaillist | sed 's/^.* <\(.*\)>/\1/g' | sed '/^$/d' | sed ':a;N;$!ba;s/\n/,/g'

# or just with a list of email addresses separated by newlines if you omit the last pipe:
# sed 's/; /\n/g' $emaillist | sed 's/^.* <\(.*\)>/\1/g' | sed '/^$/d'

# eof

Tags: sed, email

Extinction Cycle by Nicholas Sansbury Smith

April 11, 2017 — Jed Mallen

Currently on Book 3 of the audiobook series.

I like it. His concept is not of the undead but more like the Mbwun creature of Relic (Preston and Child).

Not as detailed as a Tom Clancy but it's a great post-apoc series.

Before this I got the grayman series of Mark Greaney.

Tags: audiobook, books, post-apoc

Splitting MP3s with mp3splt

March 03, 2017 — Jed Mallen

I used to just use silence detection and that was it:

mp3splt -a -t 10.0 audiobook.mp3 -d outputdir/

But when I encountered an audiobook where the silent points cannot be detected, I found the neat switch called overlap (-O).

mp3splt -t 10.0 -O 0.3 -f audiobook.mp3 -d outputdir/

The switches I used are:

-t 10.0 -- TIME in MM.SS format

-O 0.3 -- that's a capital "O" with 3 seconds of overlap on the start of the next track from the end of the previous track.

-f -- frame mode, because -O switch needs the whole book scanned first and overlaps calculated. Needed in VBR files.

Tags: mp3, mp3splt, split, audiobook