Bash style history in Power Shell

how bizarre

For those of us coming from the linux world, Power shell has a tempting assortment of linux like commands, however every so often it still feels like you are trapped in bizaro land and the commands don’t quite match up. Today was one of those days.

Bash has a great history command that will list all (or most) of your recent shell commands. In PoSH history (er ok it is Get-History under the hood) only gives you for your current session.

Fear not, there is a one-liner that will get you the history that you need and love:

Get-Content (Get-PSReadlineOption).HistorySavePath | tail -n 20

(this will get the text from your power shell history file and print the last 20 commands)

OpenMP Scheduling (default is default for a reason)

scheduling is easy, right?

This post was inspired by an interesting post from a friend and colleague about dynamic scheduling in OpenMP as well as a question that I was asked in an interview around a coding problem. (My solution as well as the interview question is at my gitlab page)

In Kyle’s problem he is implementing a naïve prime number generator where each loop takes an increasing amount of time. As he discovers, the dynamic scheduler makes the most sense in his case as each thread picks up a chunk of work (by default the chunks are sized 1). This sounds great but as with all things there is no such thing as a free lunch. Dynamic scheduling has a performance cost in added overhead.

In my case, I am leveraging the GNUMP library to run a test that will check to see if a number is very likely to be prime. Since the test takes a constant amount of time the default scheduler for Open MP ends up being the best as it does not have the overhead of the added book keeping that dynamic has. By default the static scheduler chunks the work into loop_count/number_of_threads chunks and then divides the work evenly between all of the threads.

Of note and worth further investigation is the auto scheduler where the developer yields control to the compiler to make the best scheduling decision. However this apparently requires using a better implementation than g++ and the default libgomp as it is hardcoded to take the static scheduler.

Additional References:
https://software.intel.com/content/www/us/en/develop/articles/openmp-loop-scheduling.html
http://www.inf.ufsc.br/~bosco.sobral/ensino/ine5645/OpenMP_Dynamic_Scheduling.pdf

Clearing WordPress comments via a SQL Query

Ever have a drive-by comment spammer hit you and all a sudden you have thousands of word press comments, none of them worthwhile? If you decide that you want to declare WordPress bankruptcy and just delete all of them, you either will have a long time with the batch delete button or one simple SQL query (if you have access to the back end).

First, connect to your SQL database either via command prompt or a tool like MySql Workbench. In my case, I just ssh-ed on to the server and ran the command mysql -u <<UserName>>

After logging on I ran the command show databases; to see what databases were on my server (it had been a while since I had set up my blog) and then the command use <<database name>>; to select the proper database.

I would strongly recommend making a backup of your database before doing anything for the first time…

show tables; then listed all of the tables in the database, in my case I wanted <<wordpress prefix>>_comments. Next you run the query delete from <<wordpress prefix>>_comments where comment_approved=0;

It took a while to run but afterward, all the comments were cleaned up.

ohshit-docker (or helping a friend through some docker issues

The title is from the ohshitgit website that helps users through git related problems.
As a little bit of an introduction, it is helpful to sometimes think of docker as running containers in seperate “lightweight” VMs. This is not really the case,  but it is a helpful abstraction for this brief intro.
Just to be sure where we are at lets try running a couple of commands to be sure we are in a good state.
It is an easy thing to do after a while to have a large amount of wasted space due to old and intermedate images sitting arround but not being used. An easy quick way to clean that up is with the “docker system prune”. As the warning will tell you,

This will remove:
– all stopped containers
– all networks not used by at least one container
– all dangling images
– all dangling build cache

An -a added to the command will also prune any stopped and or unused images as well.
A good way to cut down on the need to do this is to include the –rm comand to your docker run commands.

In your case of wanting to set up a zoneminder server another feature of docker is important to remember. Docker containers by default are ephemeral, that is when they exit anything that was inside the container is gone. In your case, any configurations and data will have evaporated each time you restart your computer etc. This is less than desireable.

You said that you ran the command

docker run zoneminderhq/zoneminder:latest-ubuntu18.04

Lets break down what this exactly means… you are asking the docker daemon to run the image created by zoneminderhq named zoneminder with the tab “latest-ubuntu18.04”. If we go to the docker hub we can figure out what is actually in this image. https://hub.docker.com/r/zoneminderhq/zoneminder/dockerfile and clicking on the dockerfile tab will show you what is in your container when it was built, command by command.
The issue with your set of commands as I was saying before is that you didn’t connect any ports to your local computer from the container and you didn’t mount in any folders to use as long term storage between container runs.

You more likely want to run something like is shown on the docker page:

docker run –rm -d -t -p 1080:80 \
-e TZ=’Europe/London’ \
-v ~/zoneminder/events:/var/cache/zoneminder/events \
-v ~/zoneminder/images:/var/cache/zoneminder/images \
-v ~/zoneminder/mysql:/var/lib/mysql \
-v ~/zoneminder/logs:/var/log/zm \
–shm-size=”512m” \
–name zoneminder \
zoneminderhq/zoneminder:latest-ubuntu18.04

Likely the first time you run you will need to also run before hand a script to create all the files…
mkdir ~zoneminder/
mkdir ~zoneminder/events
mkdir ~zoneminder/images
mkdir ~zoneminder/mysql
mkdir ~zoneminder/logs

So lets break down what the command is doing:

–rm cleanup any images after you exit from the container (I added this part)
-e is an environmental variable to pass into the container
-d run as detached (“daemon/service mode”)
-t allocate a psudo-tty (don’t worry about it right now)
-p expose port 80 on the container to your local port 1080
-v mount local folder to container folder
–shm sets the size of /dev/shm “tempfs”
–name an optional name (makes it easy to kill it when you want)
then the container name

By default if you don’t tell it otherwise you will start the ENTRYPOINT in the dockerfile, but if you had wanted to you could replace the -d with a -i and add to the end of the file bash and you would have a bash shell running inside the container.

You should now be able to go to http://localhost:8080/zm and see the zoneminder server.

Finally you decide that it is time to kill the container and walk away, just run the command

docker kill zoneminder

 

I originally shared this post on my github gist.

ELCA Lutheran Churches in the greater Des Moines IA Area

I have a friend who works in retail during the traditional Church hours. After some discussion I agreed to help her out and took a quick survey of all of the different ELCA Lutheran Churches in the Greater Des Moines Iowa Area (Ames, Huxley, Slater, Ankeny, Des Moines, West Des Moines etc.) By no means is this an exhaustive list, and as times and schedules change, I would recommend checking with the church or their website before trying to visit. (Sorry for the image, I just quick jotted this down using my new ebeam pen from Luidia)

ELCA Lutheran Churches of Des Moines IA

Ripping a CD to MP3 in Linux command prompt

More and more often computers don’t have CD drives. If you still have some “old fashioned” cds that you want to take with you on a trip, the linux shell can be a quick way to digitize them…

First off, if you don’t have the correct programs we will start there.

sudo apt-get install cdparanoia lame

then run the command cdparanoia -vsQ to make sure the disk and drive are working.

cdparanoia III release 10.2 (September 11, 2008)

Using cdda library version: 10.2
Using paranoia library version: 10.2
Checking /dev/cdrom for cdrom...
	Testing /dev/cdrom for SCSI/MMC interface
		SG_IO device: /dev/sr0

CDROM model sensed sensed: TSSTcorp CD/DVDW SH-S182D SB04 

Checking for SCSI emulation...
	Drive is ATAPI (using SG_IO host adaptor emulation)

Checking for MMC style command set...
	Drive is MMC style
	DMA scatter/gather table entries: 1
	table entry size: 131072 bytes
	maximum theoretical transfer: 55 sectors
	Setting default read size to 27 sectors (63504 bytes).

Verifying CDDA command set...
	Expected command set reads OK.

Attempting to set cdrom to full speed... 
	drive returned OK.

Table of contents (audio tracks only):
track        length               begin        copy pre ch
===========================================================
  1.    15485 [03:26.35]        0 [00:00.00]    no   no  2
  2.    20316 [04:30.66]    15485 [03:26.35]    no   no  2
  3.    23579 [05:14.29]    35801 [07:57.26]    no   no  2
  4.    17344 [03:51.19]    59380 [13:11.55]    no   no  2
  5.    13928 [03:05.53]    76724 [17:02.74]    no   no  2
  6.    14954 [03:19.29]    90652 [20:08.52]    no   no  2
  7.    18415 [04:05.40]   105606 [23:28.06]    no   no  2
  8.    13386 [02:58.36]   124021 [27:33.46]    no   no  2
  9.    17697 [03:55.72]   137407 [30:32.07]    no   no  2
 10.    22469 [04:59.44]   155104 [34:28.04]    no   no  2
 11.    16163 [03:35.38]   177573 [39:27.48]    no   no  2
 12.    15423 [03:25.48]   193736 [43:03.11]    no   no  2
 13.    18116 [04:01.41]   209159 [46:28.59]    no   no  2
 14.    20106 [04:28.06]   227275 [50:30.25]    no   no  2
 15.    18373 [04:04.73]   247381 [54:58.31]    no   no  2
 16.    26250 [05:50.00]   265754 [59:03.29]    no   no  2
 17.    15166 [03:22.16]   292004 [64:53.29]    no   no  2
 18.    18664 [04:08.64]   307170 [68:15.45]    no   no  2
TOTAL  325834 [72:24.34]    (audio only)

Then run cdparanoia -B to begin the rip (make sure you are in the folder you want to be in…

cdparanoia III release 10.2 (September 11, 2008)

 
Ripping from sector       0 (track  1 [0:00.00])
	  to sector  325833 (track 18 [4:08.63])

outputting to track01.cdda.wav

 (== PROGRESS == [                              | 015484 00 ] == :^D * ==)   

outputting to track02.cdda.wav

 (== PROGRESS == [                              | 035800 00 ] == :^D * ==)
.....
...
...
outputting to track18.cdda.wav

 (== PROGRESS == [                              | 325833 00 ] == :^D * ==)   

Done.

After this finishes you will need to convert over to a more compact format (optional) like mp3.

for t in track*.wav; do lame $t; done

the end result will look something like

LAME 3.99.5 64bits (http://lame.sf.net)
...
...
...
...
LAME 3.99.5 64bits (http://lame.sf.net)
Using polyphase lowpass filter, transition band: 16538 Hz - 17071 Hz
Encoding track14.cdda.wav to track14.cdda.mp3
Encoding as 44.1 kHz j-stereo MPEG-1 Layer III (11x) 128 kbps qval=3
 Frame | CPU time/estim | REAL time/estim | play/CPU | ETA 
 14025/14025 (100%)| 0:05/ 0:05| 0:05/ 0:05| 61.562x| 0:00 
-------------------------------------------------------------------------------
 kbps MS % long switch short %
 128.0 100.0 87.2 6.4 6.4
Writing LAME Tag...done
ReplayGain: -2.1dB

Congratulations! (Credit: most of these directions were inspired from article)

 

 

Christmas 2017

DennerChristmas2017

ChristmasLetter2017(pdf with photos) (evernote)

Wow! It is hard to believe that it has been yet another year, and 2017 is almost history. As usual, a lot has happened this year.

The most significant news of the year is that in May Jess accepted a new job as a Senior Quality Assurance Specialist at Kemin Industries in Des Moines for the Human Nutrition and Health division.  KH manufactures dietary supplements for things such as eye health, weight management, immune health, and brain health using natural materials like marigolds, mint, tea, potatoes, and algae.  At her new job, she is in charge of the supplier approval and environmental monitoring programs, is a member of the HACCP and the Food Safety team, and verifying labels and other documents.  She has enjoyed the new challenges and her great coworkers as a part of a very family oriented company.  Andy continues as a Senior Software Developer at Pioneer (now the Agriculture Division of Dow DuPont). While the merger of Dow and DuPont has closed, we are all still waiting to see what new opportunities this will bring.

This year was filled with many travels. We started by joining friends on a Western Caribbean Cruise aboard the Norwegian Getaway. Stops included Roatan Island in Honduras, Belize, Cozumel and Costa Maya, Mexico. It was fun visiting the Mayan Ruins of Tulum and Nim Li Punit, a Belize spice farm, as well as just relaxing on the beach. The trip was a change from our usual solo travels as we were a part of a group of friends as the trip was organized by one of our friends from marching band. Over the 4th of July weekend, we also took a short trip to Nashville where we toured the Country Music Hall of Fame, RCA Studio B and enjoyed great food and music. Finally, as part of the AΣK National Convention we traveled to Denver, CO. While Jess was in meetings, Andy toured the Coors Factory and met up with a coworker and his wife. Then we both visited Jess’ family and the Garden of the Gods. Finally, we are concluding our yearly travels with a trip to Memphis to celebrate the New Year and attend the Liberty Bowl to watch the Cyclones vs. the University of Memphis.

Jess and Andy have continued to be involved with many groups. Andy finished his term on the ISU Alumni Band board as a Director At Large and continues to serve as the President of the Central Iowa Linux Users Group. Jess still has one year remaining on the Council at Church. She also was rather busy with her baking at the Iowa State Fair where she received 11 ribbons for cakes/cupcakes, pies, and cookies including a 2nd place for monster cookies.  Unfortunately this year, none of Andy’s photos were accepted for the State Fair Photo Competition.

We hope that everyone had a great year and we look forward to the next adventure!

Merry Christmas,

 

Andy and Jess

 

In Support of net nutrality

Internet
With today being the “Save the internet day” (again), The following is a letter I sent to my congressional delegation:

Dear Sir:
I am writing out of concern and support for the FCC’s Open Internet Rules, a.k.a. Net Neutrality. As a Senior Software developer at a large Agricultural Company, owner of my own small Web Development business and the president of the Central Iowa Linux User’s Group I feel that this is an area that I am well acquainted with and would be more than happy to speak further with you or your staff in detail about.
I don’t want ISPs to have the power to block websites, slow them down, give some sites advantage over others, or split the Internet into “fast lanes” for companies that pay and “slow lanes” for the rest.
The current Internet environment that we all have enjoyed has developed and thrived because those above ideas have been prevented due to FCC regulations as well as a spirit of sharing and equality on the Internet.
Censorship by ISPs is a serious and looming problem, however. Comcast has throttled Netflix, AT&T has blocked facetime, Time Warner Cable has throttled the game League of Legends, and Verizon admitted that it will create fast lanes for sites that pay (and slow lanes for everyone else) if the FCC lifts the rules. These practices hurt consumers and businesses large and small especially in Rural and small communities as they often have fewer ISP choices to begin with.
Courts have made it clear that if the FCC ends Title II classification, the FCC must let ISP’s offer “fast lane” access to websites for a fee and Charman Pai has made clear that he intends to do exactly this.
If some companies can pay to make their sites load faster, it will help stifle startups and smaller businesses that can’t pay. This will kill the open market that has enabled millions of small businesses all to just further enrich a few cable giants.
Internet providers will be able to impose a private tax on every sector of the American economy.
Furthermore, under Chairman Pai’s plan ISPs will be able to make it more difficult to access political speech that they don’t like. They’ll be able to charge fees for website delivery that will make it harder for blogs, non-profits, artists, and others who can’t pay up to have their voices heard.
I am sending versions of this letter to the FCC’s open proceeding, but I am concerned that Chairman Pai (a former Verizon lawyer) has already made his plans and will ignore the concerns of myself and millions of other Americans. Therefore I urge you and the rest of the Iowa Delegation to publically support net neutrality based on Title II and denounce Chairman Pai’s plans.
Respectfully yours,

Andrew Denner

Visiting Rome

 

As part of our ongoing travel log here is a brief overview of some of the cool things we saw in Rome as well as some of the things we learned along the way.

Getting to our Air B&B:
As you exit the airport going towards the train station, one of the stalls that you can visit in the station will be a van service that will take you to where you need to go. It is much easier than trying to solve the situation of how to navigate the train with your luggage. Even money your air b&b host will use what’s app (everyone does). If you use the sim card (see the previous post), have google FI, or some other international coverage you should be fine.

DSC_0022

After you get in, grab a slice of pizza and catch your breath. It was a long flight and you probably want to freshen up and perhaps catch a quick nap. If you planned ahead your Roma pass is probably ready to pick up. I would recommend taking at least one lap around town to see the sights on the hop on hop off bus. There is a nice audio tour (if your jack works) and the views are much better than the subway. After you have been around once, the subway will be faster and more direct. Trust google maps, it will tell you what routes to take, and when the next train/bus will be by. It may list multiple routes as possibilities, don’t worry just pick one.

Cool stuff you need to see:
The Vatican, they have a huge amount of history, you won’t see it all! On Wednesdays the pope has a talk (if he is in town) you can get tickets from the American Catholic Church (They don’t even care if you aren’t Catholic) They will ask for a small donation, don’t be a dick and give them something nice. It will be a big to do and it is worth it just to see the crazy crowd that the pope attracts, he is really a rock star. Be sure to get there early so that you can get a good seat. Also, enjoy watching the Swiss guard. They may wear funny costumes but they mean business.

St Peter's Square before the Pope's Speach

The Flavian Amphitheater (The Coliseum) and the forum:
This is a must see! Spring for the audio tour as there is a lot to learn here! As with the rest of the trip, be sure to lace up your walking shoes as there will be a lot of walking going on!

Flavian Amphitheatre Panarama
DSC_0199

Getting a drink:
Be sure to pack a water bottle as it will be hot dry and dusty work walking around town. The good news is that there are potable water drinking fountains all around town on the street. If the fountain is running and there is not a sign telling you not to drink, and it doesn’t look too decorative it is safe to drink, just as people have been doing for thousands of years. The city of Rome has some of the best drinking water in the world, it is safe, don’t worry. The good news is if you don’t want to go this route, bottles of water can be had for not too much money.

DSC_0703

The National Roman museum:
There are great statues on the first floor, but be sure not to miss the basement where a full history of Roman coins are on display in the numismatic exhibit from the dawn of time all the way to the euro. It is one of the first museum displays that I have ever seen built into a vault.

DSC_0307

Catching a train:
Bad news, your American credit card probably won’t work in the automated machines. We have chip and signature instead of chip and pin like the rest of the world. You will have to wait in line to talk to a person. Take a number and be prepared for a long wait! Be sure to do this at least a day before you are trying to go anywhere since this will take a while.

Visiting the beach:
There are beaches accessible from the subway/train, you will have to pay a small fee to get in but it is worth it, be sure to pack a towel though as they are quite expensive there. After you get off the train station just ask at the ticket counter for lido and they will point you in the right direction. People have been coming to the beach here since the days of Rome and for a good reason. This is a great way to relax and unwind after several days of running around the country.

 

The joys of a server upgrade. 

After many years (too many) of sitting on the same old VPS at Linnode, I decided that it was time for a spring cleaning. I found a nice cheap VPS that was advertised on facebook for ~$10 a month (I know) for a not too bad amount of disk CPU and memory. The only drawback that I have really seen is that it only offers ipv4 addresses (what?! this is 2017) and it’s IP address is in a seedy neighborhood as apparently in a previous life it was an open proxy.

Servers

Now I just need to go through the process of migrating my web pages, databases and other files over and turn off the old VPS.

Thankfully I use CloudFlare so the lack of ipv6 and the crappy IP history does not bother me that much. Watch for future writeups on the migration process.