Add source url to content copied from your site

Ever wonder how the url gets added when you copy something on some websites? There are plugins and websites that do it (for money or registration), but they also appear to track clicks, so I was a bit paranoid. It isn’t so difficult and is very useful.

Basically, what happens is that whenever content from the page is copied to the clipboard, the url (or other text you want) gets added to the copied content automatically. This is useful if someone copies content from your website – often for email (as it turns out in my logs). Your page where it got copied from gets added automatically.

I have also found it useful when I want to tweet quotes from an article on the site. Instead of copying the quote and url separately, selecting the text I want gives me the content for the tweet.

Here is the javascript I am using. Feel free to edit what will be added to the content (change the square brackets before using – the code isn’t getting posted as content as javascript).

[script type="text/javascript"]
function addLink() {
var body_element = document.getElementsByTagName('body')[0];
var selection;
selection = window.getSelection();
var pagelink = "
Source: "+document.location.href; // change this if you want
var copytext = selection + pagelink;
var newdiv = document.createElement('div');
newdiv.style.position='absolute';
newdiv.style.left='-99999px';
body_element.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);
window.setTimeout(function() {
body_element.removeChild(newdiv);
},0);
}
document.oncopy = addLink;
[/script]

Redirect www to non-www on Nginx

How to redirect the www.domain.com version of your website to domain.com version on Nginx?

Here is how. You basically have to make two server blocks. The block with your normal configuration should be the version you want, the version you want to redirect should have a simple rewrite rule alone.

For example, to redirect www.vidyut.net to vn.vidyut.info/, you set up your server blocks like this:
server {
server_name www.vidyut.net;
rewrite ^(.*) https://vn.vidyut.info/$1 permanent;
}

server {
server_name vn.vidyut.info/;
# Your
# normal
# server
# configuration
# goes
# here
}

Random Tweet Assistant if you hate sickular people

After getting thoroughly fed up of highly repetitive trolls not even able to insult with any creativity, here is a writing aid to help single-digit IQs to insult “sickulars” with some flair at least. I mean, if you must look like an idiot, at least look like pretty idiot, yes?

[otw_is sidebar=otw-sidebar-1]

Most of these are conversation aids, perhaps not proper insults, but at least they give you something to say, beyond “you anti-national,you!”

While right wing trolls are an overwhelming area of boredom, there are others. I’ll check how this page goes before creating more insult assistants.

Feel free to add suggestions (with or without source) in the comments.

How to install ioncube loader on Ubuntu in one line of code

To install ioncube loader on Ubuntu, AS ROOT paste this line:

cd /usr/local && wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz && tar xzf ioncube_loaders_lin_x86-64.tar.gz && echo "zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.3.so" | sudo tee /etc/php5/conf.d/ioncube.ini

If you are using nginx, that would be:

cd /usr/local && wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz && tar xzf ioncube_loaders_lin_x86-64.tar.gz && echo "zend_extension=/usr/local/ioncube/ioncube_loader_lin_5.3.so" | sudo tee /etc/php5/fpm/conf.d/ioncube.ini

Please note that if you are using symlinks and maintaining a single php.ini and conf.d folder instead of separate ones for php5 and php5-fpm (good idea if you switch between apache2 and nginx), either one of the lines will work.

Restart php5 or php5-fpm as the case may be.

sudo service apache2 restart

or

sudo service php5-fpm restart

Chromium starts about:blank tabs on typing into dashboard in Ubuntu

This is a strange and inexplicable error. Typing into the Ubuntu dashboard spawns new tabs in Chromium. This happens even if Chromium is not running it simply launches and spawns one or more tabs.

Sometimes this also happened when software updater started.

I had Chromium as the default browser earlier and made Firefox the default to fix this problem. It did not work.

What worked was logging out and logging back into my Google chat account in Online Accounts.

No idea why this is so, but turns out that it is a Chromium bug and what I did intuitively (after trying many other things that didn’t work) was a fix.

Nginx: upstream timed out (110: Connection timed out)

Error 110: Connection timed out while reading response header from upstream

Sometimes a Nginx web server seems to load pages with php code with a lot of xml parsing really slowly. Often it doesn’t load or connection times out. This will be seen more on pages where the php code parses through large xml files and outputs data only when all the parsing is complete. The Nginx web server times out before php returns output.

We have to make the Nginx web server wait more before giving up on the upstream.

This is a typical error I get:

upstream timed out (110: Connection timed out) while reading response header from upstream

or

connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream

and such. The second one is inexplicable, since everything is working when not timing out, but I have often seen these two together.

The fix that works is increasing the timeout.

In the server configuration /etc/nginx/nginx.conf on Ubuntu/Debian, in the http {....} block, add the line (or edit the commented out line)
fastcgi_read_timeout 300s;

Restart the Nginx web server (as root or with sudo).
service nginx restart

There should be an immediate improvement when parsing large xml files. If you are still having problems, raise the number till resolved.

English: Nginx Logo Español: Logo de Nginx

English: Nginx web server Logo Español: Logo de Nginx (Photo credit: Wikipedia)

Enhanced by Zemanta

Fix a broken mysql

If your mysql seems broken and giving errors like:

# service mysql start
start: Job failed to start

or

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Or if you try to recreate databases with mysqlinstalldb:

...
...
ERROR: 1  Can't create/write to file './mysql/db.frm' (Errcode: 13)
041226 xx:xx:xx /usr/libexec/mysqld: Can't find file: './mysql/db.frm' (errno: 13)

or all your databases go missing, even if you reinstall mysql-server.

and reinstalling mysql-server won’t work,

Before you reformat the server and use your data, you should try doing (as root, or using sudo):

apt-get install --reinstall mysql-server

chown -R mysql:mysql /var/lib/mysql

I don’t know how, but somehow the permissions get changed and mysql can no longer operate, or a reinstalled mysql still can’t see the tables. They are not gone, they are there. mysql can’t see them and that can be fixed.

Note: Some complained that if they do:

apt-get install mysql or apt-get remove mysql

They get the error that the package can’t be found. Something like:

# apt-get remove mysql
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package mysql

That has nothing to do with this. This happens because the package for mysql in the repositories is mysql-server and not mysql alone. Doing apt-get install mysql-server will work.

How to retrieve your passwords saved in Google Chrome or Chromium on ubuntu linux

If you are like me, you have loads of passwords saved in the Chrome browser. And then you need them. Maybe you want to stop using Chrome, or you want them to enter into some applcation other than the browser… or perhaps you just want a list of all sites you have passwords for – curiosity… whatever the reason, it isn’t easy to discover how to do this.

This solution is based on one I found at The Big Browser with two very minor changes where that code didn’t work for me.

Before beginning, make sure you are signed in from your Google Chrome or Chromium browser and your passwords are synced and available.

Close the browser.

Next, open the browser from the command line, with a temporary profile that stores passwords without encryption. Like so (pick one of the lines depending on the browser you are using)

### Google Chrome
    google-chrome --user-data-dir=/tmp/chrome-tmp --password-store=basic

### Chromium
    chromium --user-data-dir=/tmp/chrome-tmp --password-store=basic

This did not work for me – I use Chromium. I had to use this:

### Chromium
    chromium-browser --user-data-dir=/tmp/chrome-tmp --password-store=basic

I have no idea what happens with Google Chrome, but if the given line doesn’t work, appending -browser to google-chrome is worth a try.

This will open a separate session. Sign in to the browser with your account and wait for a while till your passwords are synchronized. You can surf if you want. When your data is syncronized, your saved websites and bookmarks will be available. You can go to “Manage passwords” in settings and see that your passwords are loaded. If you don’t see them, wait some more time till you do.

Close the browser.

Note: the fastest way to get to the stored passwords page in settings is to type password in the Search box in the top right.

In the terminal, enter:

cd /tmp/chrome-tmp/Default

For the next step, you will need sqlite3 installed. If it isn’t installed, you can install it by entering:

sudo apt-get install sqlite3

Then enter:

sqlite3 'Login Data'

At the changed prompt, now enter the following lines one by one.

.mode csv               # other options are `html', `tabs', etc.
.headers on
.separator ","
.output chrome_passwords.csv
select * from logins;
.exit

This will give you a file called chrome_passwords.csv with your Chrome passwords.

To open it with LibreOffice, type:

libreoffice --calc chrome_passwords.csv

The passwords will open as a spreadsheet. You also will be able to import this spreadsheet into other keyword managers if you need to.

Update/install fail: Server cannot access software repositories

If you are trying to install something and the server waits forever after you answer yes to the update and it accesses the software repository… something like…

apt-get update
...
details of packages
...
Need to get 83.7 MB of archives.
After this operation, 237 kB disk space will be freed.
Do you want to continue [Y/n]?
0% [Connecting to archive.ubuntu.com]

And then nothing. It fails.

Do you have UFW installed? UFW can block outgoing connections from your server, so it becomes unable to access the software repositories. Rather than make exceptions, it is easier to disable the firewall and enable again when update or install is done.
??
If you have UFW (Uncomplicated Firewall) installed, disable it and try again.

ufw disable

Now your upgrades should work. Once you are done, re-enable your firewall.

ufw enable
Enhanced by Zemanta

bash: add-apt-repository: command not found

If you are trying to add a ppa repository and get the following error

bash: add-apt-repository: command not found

You need to install python-software-properties, like so

apt-get install python-software-properties

If you have python-software-properties installed and are still getting this error, there is some problem with the package. Uninstall and reinstall it.

apt-get remove python-software-properties --purge && apt-get install python-software-properties

or

apt-get install --reinstall python-software-properties && sudo dpkg-reconfigure python-software-properties
Enhanced by Zemanta