Monday, August 25, 2014

Setting up ghost on the Openshift

In past few days I decided that I would like to keep track on my progress in how I learn new stuff. After some consideration I hope a good way to organize my work would be to use Ghost: is just a blogging platform funded on Kickstarter last year. I have heard all the hype when Ghost got funded and tried to use it early on, but it was disaster to when it was first released. Also, I didn't have a good use case to keep working at it, but now... here is an opportunity.

Quick googling ghost resulted in number of links as a community seem to be sprouting around it. I read a good introduction on setting it up and on its current features on "Ghost for Beginners". The site covers how to set Ghost on Ghost(PRO), AWS and DigitalOcean, but there was nothing about my favorite hosting solution - OpenShift. So I figured I can write a post on setting Ghost on OpenShift.

At first I tried to set it up using OpenShift's console, but that yielded in an error:



Attempting to install through web interface failed twice, I was a bit discouraged, so finally I attempted to try running rhc command from terminal. That worked like a charm:

rhc app create ghost nodejs-0.10 --env NODE_ENV=production --from-code https://github.com/openshift-quickstart/openshift-ghost-quickstart.git

And here is terminal output:

Application Options
-------------------
Domain:                _MY_DOMAIN_
Cartridges:            nodejs-0.10
Source Code:           https://github.com/openshift-quickstart/openshift-ghost-quickstart.git
Gear Size:             default
Scaling:               no
Environment Variables: NODE_ENV=production

Creating application 'ghost' ... done

Waiting for your DNS name to be available ... done

Cloning into 'ghost'...
The authenticity of host 'ghost-_MY_DOMAIN_.rhcloud.com (54.82.127.129)' can't be established.
RSA key fingerprint is cf:ee:77:cb:0e:fc:02:d7:72:7e:ae:80:c0:90:88:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ghost-_MYDOMAIN_.rhcloud.com,54.82.127.129' (RSA) to the list of known hosts.

Your application 'ghost' is now available.

  URL:        http://ghost-_MY_DOMAIN_.rhcloud.com/
  SSH to:     53fba91d5004466ac7000306@ghost-_MY_DOMAIN_.rhcloud.com
  Git remote: ssh://53fba91d5004466ac7000306@ghost-_MY_DOMAIN_.rhcloud.com/~/git/ghost.git/
  Cloned to:  /Users/_MY_USER_/Source/ghost

Run 'rhc show-app ghost' for more details about your app.

Ghost correctly appears in the console after that:

Here is a snapshot of Ghost homepage:

I added the user, and published test post:


Adding a custom domain name boils down to:
    1. add an alias using RHC
       rhc alias add ghost MY_CUSTOM_NAME.MY_DOMAIN.COM
    2. setting up DNS alias:
       from: MY_CUSTOM_NAME 
       to: ghost-_MY_DOMAIN_.rhcloud.com
       as: CNAME (alias)

I use namecheap.com and have had a great experience with them for a couple of years now. They have very easy to use admin panel (not the most intuitive, but very efficient).

Adding google analytics to the blog:
  go to your RHC folder with the application
  edit file: content/themes/YOUR_THEME/default.hbs
  just before end < /head> tag insert your GA code.
  git commit -a # to commit to code repository
  git push # to push to OpenShift

I will update this post with other steps I plan to undertake, staring from ensuring that there is a scheduled backup, over adding google analytics and google adsense to the blog.

Thursday, May 22, 2014

FIX: Django, uwsgi, Apache, ProxyPass, host is localhost and using ProxyPreserveHost

I just spent some time trying to figure out how to set our Django application.

Our setup is:
  Apache (handles HTTPS and client certificates) is front-end proxy to uwsgi
  uwsgi is used to run Django application in the backend.

The problem we faced is that our redirects were broken as links build by django used 'localhost' instead of name of the virtual host. After looking through solutions, and finding some of the issues like:


I looked into django handling of get_host() and tried to understand what's happening.
Long story short, Apache passed HOST header as 'localhost', this led to search of apache documentation, as I was thinking that I reset headers using 
   RequestHeader set X-FORWARDED-PROTOCOL ssl
   RequestHeader set X-FORWARDED-SSL on
   RequestHeader set X-FORWARDED-HOST *hostname*
   RequestHeader set HTTP_HOST *hostname*
   RequestHeader set HOST *hostname*
but apparently, apache does not pass these through the proxy... so... drumroll, saving grace is:
and side note, ProxyPreserveHost needs to be on the VirtualHost level or higher.

I hope this short post will save you some time :)

Tuesday, March 11, 2014

MacOSX & Chrome: How to make scrollbars ALWAYS visible in your web application

If you are, like me, annoyed that overflow: scroll does not display scrollbars on all MacOSX computers in chrome; you can actually force Chrome to behave by just adding this to your CSS:


::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 7px;
}
::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background-color: rgba(192,192,192,.3);
    -webkit-box-shadow: 0 0 1px rgba(255,255,255,.5);
}


Friday, February 28, 2014

How to calculate MD5 and SHA1 fingerprints using web browser?


Downloads and fingerprints

MD5 and SHA1 fingerprints often listed next to the large files one can downloads from files are there to ensure that data downloaded is the same as the data on the server. It is a good policy to always check if downloaded file has the same fingerprint as the one provided from the trusted source.

How to perform MD5 or SHA1 check using web browser?

While you can download the command line tools (shasum and md5sum) or use GUI tools to calculate MD5 and SHA1 checksum, it seems that today's browsers should be suited to let you do that calculation without resorting to specialized applications. One such tools that does not require you to download software, but lets you check MD5 and SHA1 sums right from the browser is Checksum MD5 and SHA1 calculator. This handy tool let you pick one or more files, and without uploading them anywhere check them right from the comfort of your device. It works with most of the modern browsers (IE10+, Chrome, Firefox, Safari) and it even works with your mobile devices if you ever need to do that sort of calculation (for example for .apk you just downloaded).


Monday, February 7, 2011

Dropbox (Error code -36)

Today, I was faced with Dropbox 'Error 36' on MacOS.
So, let's start from beginning... Dropbox has file name limitations, and those limitations are a bit different than operating system limitations (MacOSX).
I am convinced that there are good reasons for these, as they have special meaning on the command line level or would look really weird in the browser.

Let's start with the issues:
- Issue 1: File names can not start or end with blank character
- Issue 2: File names should not contain slashes

Where issue 2 is easy to spot, finder does not make it easy to spot issue 1. Thus I have created a short script that fixes blank characters in file names.

You can download dropbox_fix_script.pl. You need to navigate to the folder you are trying to copy, unzip and run this script from terminal.

Before you run this script, make sure to backup your data.

If there are enough interested readers, I may wrap this into application that you can drop a folder on.

--- script content is:
#!/usr/bin/env perl
#
sub fix()
{
    my @list = `find .` ;
    chomp(@list);
    for my $file (@list)
    {
    print "." ;
    my $base = `basename "$file"` ;
    my $dir = `dirname "$file"` ;
    chomp($base);
    chomp($dir);
        if( ($base =~ /\s+$/) || ($base =~ /^\s+/) || ($base =~ /\// )
        {
      print "match $file\n" ;
          $base =~ s/\s+$//mig ;
          $base =~ s/^\s+//mig ;
          $base =~ s/\//_/mig ;
    print "\n" ;
          return ( $file, "$dir/$base");
        }
    }
    return undef;
}

while( 1 )
{
    my ($file, $new_file) = &fix();
    if( defined( $file ) )
    {
        print "rename '$file' '$new_file'\n" ;
        if( -f $new_file )
        {
            print "file already exists $new_file -- fix $file \n" ;
            exit ;
        }
        if( -d $new_file )
        {
            print "dir already exists $new_file -- fix $file \n" ;
            exit ;
        }
        rename $file , $new_file ;
    }
    else
    {
        last;
    }

}

Wednesday, January 26, 2011

DNA reverse complement

Just published simple DNA reverse complement tool. It features reverse sequence generation, complementary RNA and DNA generation and of course reverse complement for both DNA and RNA. Check it out.

Wednesday, January 19, 2011

Click-o-mania and cyclick-o-mania in pure HTML

Last time I wrote click-o-mania clone was in summer of 1999. I wrote it in an MIT Athena cluster one summer day with the idea that it would help me with, than fresh Java skills.

Now the time has come, and I wanted to work on my GWT skills - thus - new HTML only, Flash-free, Java-free version of Click-o-mania and cyclick-o-mania are available. This simple games are written in using GWT/Java and compiled and tested on Mac and Windows, in variety of browsers and also adapted to work on iPhone. If they work well on Android, I would be interested to hear.

I hope you will enjoy these games as much as I enjoyed writing them.