Thursday, January 26, 2017

How to generate a Dockerfile from an image?

So easy, it hurts:

$ docker pull image/I/Want/To/Inspect 
docker history --no-trunc image/I/Want/To/Inspect

Done

Monday, July 6, 2015

How to deal with 'no space left on device' error when using Docker on OS X

When time is money, sometimes starting from scratch is way more efficient than trying to salvage your data. Recently I got the famous 'no space left on device' when trying to build a container with python, maven and boost. I found this, but immediately imagined the amount of time/effort, and weighed out that it was not worth it.

If you are like me, then you already use Docker as a temporary system, so rebuilding images is not a big deal. In that case, I suggest you do the following:

Add the following to ~/.boot2docker/profile:

# Disk image size in MB 
DiskSize = 40000

This will increase your boot2docker VM to 40GB.

What next? Easy: you destroy everything and start from scratch.

boot2docker stop 
boot2docker destroy 
boot2docker init 
boot2docker start

Thursday, August 7, 2014

On building websites: Comparing Scala/Play vs GO

I just pushed code to <https://github.com/talmai/gemawebsite> where I have the very same website coded to run on Scala 2.9.2  + Play 2.0.2, and on Go 1.3. Both code work, and generate the same output (checkout www.gemaestudio.com).

As of today, when given an option, I will choose Go over Scala anyday. The code speaks for itself. But out of curiosity, I took a look at memory and cpu requirements... (screenshots below are from the 'top' command).

VIRT stands for the virtual size of a process. In a nutshell we are talking about the sum of memory it is actually using (memory it has mapped into itself, shared libraries, and memory shared with other processes). VIRT represents how much memory the program is able to access at the present moment.

RES stands for the resident size, which is an accurate representation of how much actual physical memory a process is consuming. (This also corresponds directly to the %MEM column.) 

Scala uses 74MB of RAM (RES), but 297MB for VIRT. 


Go, as expected, uses only 5.4MB of RAM (UPDATE: to be honest, it's more like 3.8MB), but has mapped 828MB (VIRT). This I didn't expect.


Anyhow... it was fun while it lasted. The awesome part is knowing how much more RAM I got freed up on my box after this exercise. ;)

Thursday, October 17, 2013

How to combine multiple worksheets into one in Excel? (using vba)

I have several excel workbooks (.xls files) and each workbook contains multiple worksheets. The number of worksheets (as well as their names) are not constant. Each worksheet is formatted in the same way (i.e: same header). Now I want to copy all the data on each worksheet and copy it into a single worksheet. 

Launch an Excel file that you want to combine other workbooks into. Click Developer > Visual Basic, a new Microsoft Visual Basic for applications window will be displayed, click Insert > Module, and input the following code into the Module. 

Oh, and before that, create a sheet called "Summary" where we will collect the info.


Sub SummarizeSheets()
    Dim ws As Worksheet
    Application.ScreenUpdating = False
    Sheets("Summary").Activate
    Path = "C:\path\to\your\files\"
    Filename = Dir(Path & "*.xls")
    Do While Filename <> ""
        Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
            For Each Sheet In ActiveWorkbook.Sheets
                For Each ws In Worksheets
                    If ws.Name <> "Summary" Then
                        ws.Range("A01:AX201").Copy
                        ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
                    End If
                Next ws
            Next Sheet
        Workbooks(Filename).Close
        Filename = Dir()
    Loop
End Sub
Then click doc-merge-multiple-workbooks-button button to run the code, and all of the worksheets (including the blank worksheets) within the workbooks have been merged into the master workbook.

References: http://www.extendoffice.com/documents/excel/456-combine-multiple-workbooks.html

Sunday, July 21, 2013

bit-for-bit copy of DVD on osX (or: how to generate .iso on mac)

0) Insert DVD
1) Open up terminal
2) Find out where it was mounted (diskutil list)
3) unmount it (sudo umount /dev/disk1)
4) generate .iso (dd if=/dev/disk1 of=~/dvdImage.iso bs=2048 conv=sync,notrunc)

Monday, August 6, 2012

How to install django-celery in windows (python, django, celery, erlang, rabbitmq)

A project of mine goes through a realistic simulation that doesn't take too long (15 seconds), but that, unfortunately is about 15 seconds too long. So I had to find a workaround for it. Threads was the first thing that came to mind, but Python is worthless for this....

Anyhow, let's get straight to the point:

***************************************
Install erlang
Install RabbitMQ


pip install kombu
pip install celery
pip install django-celery

the above commands might cause errors for sub-installation of kombu and billiard. If this occurs:

install MinGQ
in the directory for billiard (ex: C:\Users\YOUR_USER_NAME\build\billiard)
run: setup.py install build --compiler=mingw32

then rerun:

pip install kombu
pip install celery
pip install django-celery

then update settings.py according to following link and run SyncDB:
***************************************

Credits: I have Dan (http://www.linkedin.com/pub/dan-ziembienski/17/720/679) to thank for this.

Monday, July 2, 2012

Scala 2.9.2, Play! 2.0.2, and Amazon EC2

Summary: I describe how to setup a domain on amazon's EC2 (using my personal named server), and the tricks on getting scala + play (2.0.2) to run on a micro instance.

---

Introduction: So recently I got an iphone and while out and about, I wanted to look at the source code of a page on safari. It so happens that I can't do that. (Yes, I know, I took it for granted.) So while there are some apps out there, I refuse to buy an app that I'll use only once. As a matter of luck, it so happened that this weekend there was a "$.99 .com" sale, so I hastily grabbed "www.seesster.com", and considered building a site that "sees what your browser sees".

It so happens that I've been been reading about Scala as well as the Play framework, and Friday night started to code seesster up. I won't go into details of the Scala/Play code and what I'm doing (long story short: scala + phantomjs + pygments), but I will describe how I was able to set this up (running!) on my free amazon EC2 micro instance.

DNS and sub-domains: So when I login to my AWS management console, there are two things that need to be done:

1) I need to name my instance with the exact subdomain I am planning on redirecting the service to. In this case, I've named the instance www.seesster.com

2) I also need to jot down the Public DNS (which I'll use for the CNAME entry of my named config file). In this case, it is ec2-174-129-174-216.compute-1.amazonaws.com

I've highlighted the entries I'm talking about in red....
Next up, I need to update the config file. While I won't show you the whole file, as long as you know *anything* about setting up your own DNS server, this should suffice... In a nutshell, we need to setup a CNAME entry that points to the public DNS. Note the "." after the url string.

www    CNAME    ec2-174-129-174-216.compute-1.amazonaws.com.


At this point, when I tried "www.seesster.com" I would correctly end up on amazon's server. However, this was the easiest part of my weekend.

Play won't run: My coding environment has plenty of memory, so I never thought once on how this could impact me. That is, until I tried to run play on it... "play run", "play dist", "play start" and even "play compile" would end up with memory allocation problems. I was between a rock and a hard place.

Solving this involved:

1) Manually downloading and installing java 1.7 (jdk1.7.0_05).
2) Updating the symbolic links:

$ ll /usr/lib/jvm/jre
lrwxrwxrwx 1 root root 31 Jul  2 03:09 /usr/lib/jvm/jre -> /home/ec2-user/jdk1.7.0_05/jre/

$ ll /usr/bin/java
lrwxrwxrwx 1 root root 35 Jul  2 03:10 /usr/bin/java -> /home/ec2-user/jdk1.7.0_05/bin/java

3) on my dev box, running "play dist" and uploading that stand-alone file to amazon
4) updating the "start" script in the stand-alone folder to:

$ cat start
#!/usr/bin/env sh

exec java -Xms64M -Xmx128M -Dhttp.port=80 $* -cp "`dirname $0`/lib/*" play.core.server.NettyServer `dirname $0`

What this allows me to do is run my play application with limited memory usage on port 80. (Reminder: this is on Play 2.0.2).

Happy ending: Cool or not cool? As of today, www.seesster.com is running and working. I will be updating code during the week for sure. If you are reading this in the future (wow!), and the site doesn't work, I am probably aware of it. After all, a year from now the domain will expire. And unless it is making me money, I'll probably *not* renew it.

:)