use your browser as a private pastebin

Standard

I’ve never a big fan of pastebin ever since I discover this trick to turn your own browser into a place to copy and paste, jot down ideas or just a general paste to release all that you have in your head into written words.

The trick is to put contenteditable as an attribute for the html element, so if you put

Into your browser URL bar, it will transform this new tab you have into a notepad, editable.

You can also theme the notepad with various color scheme

Source

password-less ssh login

Standard

When you have to regularly ssh from one machine to another, for my job this is a mundane everyday task, you’ll learn to hate it that everytime you have to type in the username and password combination to authenticate yourself. If the machine is a workstation machine and only you have access to it, then there’s no reason why it shouldn’t be password-less and make ssh-ing a painless task.

This can be done easily by creating a trusted public key by using

This will make a directory called .ssh in your home directory if you do not have one, give it the right permission and run the ssh-keygen command to generate the relevant keys. You might want to give your ssh key a password during the process, but I suggest not. This is a password-less procedure anyway. Your keys will be stored as ~/.ssh/id_rsa.pub.

Let’s stay you are ssh-ing from <local_machine> to <server>. What you want to do next is to copy the file over to the server. On some machine you could just do

And it’s done. Or if your OS does not support ssh-copy-id, you simply should just run

and type if your server password for the very last time.

Next time you ssh over to the <server> machine from the <local_machine>, the handshake will commence and no password will be needed. Moreover, if you ssh from another machine, then password will still be required to retain security. Have fun!

Fix iTerm2 color scheme does not get applied

Standard

iTerm2 is probably my goto terminal replacement for my mac. This is quite essential as the default terminal of mac osx is just not pretty enough. I strive for aesthetic and pleasure in using my tools so that my productivity can be of the highest.

If for some reason, iTerm2 just doesn’t reflect the beautiful color scheme that you customised yourself, or get from some other sources, in my case, it’s the magnificent solarized dark.

This troubleshooting will fix why your ANSI color scheme doesn’t apply on your mac for iTerm2, if that is the case.

First, always make sure you have the right color preset at Preferences > Profile > Color and the right profile is being used. Also, make sure the minimum contrast slider is somewhere in the middle, not at the High level.

If this doesn’t fix the problem, open your .bash_profile and add

and then source

After that, go to Preferences > Terminal > Report Terminal and set the type to xterm-256color.

Close and restart iTerm, this should fix it for you

Install and run SOLR in Tomcat

Standard

This tutorial is for any debian based unix server that you may have, ubuntu users should use apt-get whenever possible.

Make sure java is installed, as SOLR is a Java application and would not be able to run without Java. To install java

If it fails, try

to search for any package with java in the title and try installing it. If none is found, try install the repository based on this FAQ

Install Tomcat with

Start tomcat6 with

Download a version of SOLR from one of the mirrors, I’ll be using version 4.3.1 in this guide and will be install SOLR to /usr/local/, your placement may vary

To quickly run SOLR within Jetty container

Solr should now be running in http://localhost:8983/solr

To change the Jetty port for SOLR, we run

to change the jetty port to 9999 and have SOLR running in http://localhost:9999/solr

However, SOLR is better suit to run in Tomcat rather than Jetty and it’s the entirety of this guide, so we’ll have to create a context fragment for tomcat and deploy the war file that is present in the solr_home folder we have before.

This is to create a solr instance from the example folder we have before, now we will copy the distributed solr war file to the local solr folder by

We will now prepare the apache tomcat configuration file by modifying the server.xml. The portion should look like this

We can also change the port attribute to other port, like 9999

We will now create the solr.xml context fragment and put them into tomcat6 catalina localhost

With the following

We restart tomcat6 with

and have our SOLR running on http://localhost:8080/solr

Troubleshooting

if something does not go smoothly, monitor the tomcat log by

If there are permission denied error, try having all files owned by the tomcat user by

 

 

.htaccess security

Standard

Password Protect

Besides the use of URL rewriting and redirecting. We could use plain old .htaccess file to lock down a specific folder for a handful of selected users using the following snippet.

Note that the .htpasswd file contains the credentials needed to gain access to the site. This file content is in the form

Where the password is hashed and the hash can be obtained with the following command

For example

Block Access

To block access from certain IP address

To block access from certain user agent (namely bots)

 

.htaccess rewrite and redirect

Standard

.htaccess files are files that you will put on the root of your web server as a dynamic overwrites on how URL will be treated. This can be used to a great extent in controlling your website structure.

Rewrite

A popular use for .htaccess file is to rewrite URL to achieve clean URL structure. Suppose you have a page that takes in

And you would like to achieve

This could be done easily with the following .htaccess file

RewriteRule simply takes in a regex and transform the URL accordingly, as such: anything that has page/ in it that followings with 3 things separated by slashes will be transformed to page.php?task={first_thing}&id={second_thing}&param2={third_thing} as indicated by the dollar ($) sign.

RewriteRule can also be as simple as

To show the user new.html whenever they type in current.html

Rewrite Flag for Redirection

Flags can be added on to Rewrite Rule to indicate the status of the Rewrite Rule. For example

Means that current.html is now permanently redirected to new.html and their browser will now show new.html instead of current.html

Other flags can be used for various purpose

jQuery chain ajax request

Standard

When we are dealing with ajax requests that needs to be executed in succession. These requests might need to provide feedback to the user that it has gone through successfully. Or in some case we just need to be able to provide the next request with a result variable from the previous request.

A solution is to implement a function that would execute the ajax step, like so:

Cross Browser min-height, max-height

Standard

Yes, it even works in IE

For max-height, we go for this

For min-height, we go for this

To use both at the same time

The expression value only works for IE and will require javascript, so that’s fine to use. One caveat: Dont’ use it if you have a choice.

With a little jQuery this will be even easier. This will be the DOM, note that we specified the maxHeight and minHeight as attributes

In the JavaScript, for each of those div of class constraint, we will correct the width and height accordingly

If all else fails, we could always fall back to the traditional and all-powerful conditional stylesheet, note that conditional stylesheet will only affect IE users with width and height of constraint elements be set manually.