LinuxPlanet Blogs

By Linux Geeks, For Linux Geeks.

A first Python one-liner

without comments

By Vasudev Ram

1. Install Python 2.7 (if you don't have it already).

2. Run this at the command line:

python -c "print ''.join(list(reversed('!dlrow olleH')))"

- Vasudev Ram - Dancing Bison Enterprises

Contact Page

Written by Vasudev Ram

November 25th, 2014 at 1:37 pm

Memorable Quotes – Part 4

without comments

A follow on from:
http://dtbnguyen.blogspot.com.au/2013/07/memorable-quotes-part-3.html

- Alan Shore: My, uh, best friend has Alzheimer's, in the, uh, very early stages, it hasn't... He is a grand lover of life, and will be for some time. I believe even when his mind starts to really go, he'll still fish he'll laugh and love, and as it progresses he'll still want to live because there will be value for him, in a friendship, in a cigar... The truth is I don't think he will ever come to me and say, this is the day I want to die, but the day is coming and he won't know it... This is perhaps the, the most insidious thing about Alzheimer's... but you see he trusts me to know when that day has arrive, he trusts me... to safe guard his dignity, his legacy, and self respect. He trusts me to prevent his end from becoming a mindless piece of mush and I will. It will be an unbearably painful... thing for me, but I will do it, because I love him. I will end his suffering, because it is the only decent humane and loving thing a person can do.
http://www.imdb.com/title/tt0993804/quotes
- "We are strategic but we stop at number crunching, we plan but we don't over manage, we inspire but we don't preach, we code but we're not monkeys."
http://www.seek.com.au/Job/calling-all-super-powered-geeks-to-enlist-in-the-fight-against-corporates/in/sydney-sydney/22545415 
- It was either Otto von Bismarck or Claud Cockburn who said, "Never believe anything until it has been officially denied." Whoever it was, and the internet seems a little confused on the matter, they were on to something.
http://www.smh.com.au/business/intelligent-investor/australias-most-overpaid-ceo-20130513-2jhmv.html 
- "Change is a big word that everyone is using. (United States President Barack) Obama uses it, but you have to actually feel it."
http://au.news.yahoo.com/thewest/a/-/world/17135873/adrian-cheng-updating-a-hong-kong-family-empire-for-a-changing-china/
- Sandschneider agrees that personal relations have an impact on political relations: "International politics is not a dehumanized process. It is about people coming together. And it is true that it is easier for two people who get along well to negotiate and solve problems than two people who can't stand each other."
http://www.dw.de/germany-is-first-on-lis-eu-list/a-16834332
- "Skeptics don't make history"
http://www.washingtonpost.com/world/africa/kerry-says-us-drone-program-strict-fair/2013/05/26/80058422-c615-11e2-9cd9-3b9a22a4000a_story.html?tid=pm_world_pop
- "Germany won," said Glasman at the debate. "We have a Champions League final between two supporter-owned and democratically governed football clubs. Tradition and the preservation of institutional virtue are a source of energy and modernisation precisely because change and continuity work together; a balance of power is the best system; a negotiated settlement is better than one that is imposed, the domination of any interest violates the demand of what is good; the discovery of the common good between forces that are estranged is the best good of all. It takes longer to get there but the benefits are more enduring."
http://www.guardian.co.uk/world/2013/jun/01/germany-champion-europe
- Secondly, for web site owners. Assume the entire world is out to get you. All of it; and everyone living there. It's easier that way! Do whatever you feel necessary to keep your name out of the press. Then do everything that isn't necessary, because it may-well prove to be necessary in the future. And if you're not sure what I mean, get advice, urgently.
http://www.itwire.com/business-it-news/security/58893-abc-web-site-hacked-by-opponent-to-geert-wilders
- In his seminal 1931 book, Equality, R H Tawney lamented that the public did not seem resentful of the rich so much as fascinated by their goings-on. Little has changed. For most Brits, stupendous wealth has always been something that is aspired to more than resented. The post-crash fuss about the 1 per cent often seemed to be a civil dispute between its members: well-heeled activists, journalists and union chiefs castigating those who nabbed the best tables in restaurants or pushed up prices of Tuscan villas. And as successive prime ministers have realised, no government anywhere has helped the low-paid by railing against high wages.

The rich, to adapt Jesus in St Matthew's Gospel, will always be with us; the 1 per cent are likely to pull ever further away. But this has its compensations. The lower-paid half of the British populace have never had to pay a smaller share of income tax than today, because the wealthy have never forked out more. And while there is not much David Cameron can do about the rich, there is still plenty he can do about the poor. He doesn't shout about it. But he has rightly concluded that this is where his attention is best focused.
http://www.telegraph.co.uk/finance/globalbusiness/10202546/Dont-blame-the-best-paid-1per-cent-theyre-worth-it.html
- "The problem is not ammunition, it's experience," one said, adding: "If we were fighting Americans we would all have been killed by now. They would have killed us with their drone without even needing to send a tank.

"The rebels are brave but they don't even know the difference between a Kalashnikov bullet and a sniper bullet. That weakens the morale of the men," he said.
http://zeenews.india.com/news/world/syria-iraq-yemen-and-afghan-jihadists-join-war-against-assad_801575.html
- Obama said that "at a time when anyone with a cellphone can spread offensive views around the world with the click of a button," the notion that governments can control the flow of information is obsolete.Obama said that "at a time when anyone with a cellphone can spread offensive views around the world with the click of a button," the notion that governments can control the flow of information is obsolete.
http://www.skynews.com.au/topstories/article.aspx?id=799117
- Only about 1 in 1,000 Web readers clicks on the average display ad. On Facebook, that number is closer to 1 in 2,000, according to Webtrends. Even ads sent by unsolicited postal mail generate a response rate that is many times higher, according to published industry numbers.
http://www.latimes.com/business/la-fi-facebook-display-ads-20120525,0,4871607.story
- Famous night owls include Winston Churchill, President Obama, Charles Darwin, James Joyce, Marcel Proust, Keith Richards and Elvis Presley. Famous early risers include Napoleon, Ernest Hemingway and George W. Bush.

Professor Jim Horne, of Loughborough University, said: "Evening types tend to be the more extrovert creative types, the poets, artists and inventors, while the morning types are the deducers, as often seen with civil servants and accountants.
http://www.theglobeandmail.com/life/the-hot-button/like-staying-up-late-you-may-be-narcissistic/article13495020/comments/
- Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed.

This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter with a half-million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. . . . This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron.[1][4]
http://en.wikipedia.org/wiki/Chance_for_Peace_speech
- Decades of reform. Globalisation, and the global financial crisis. The uncertainties of the post-September 11 world. Eric Knight: "Those circumstances are ripe for misinterpretation, for populist interpretation, interpretation that focuses on the surface of things and often misses the deeper logic of what's happening."
http://www.smh.com.au/opinion/political-news/history-repeats-20120504-1y4ki.html
- "Falling in love is very real, but I used to shake my head when people talked about soul mates, poor deluded individuals grasping at some supernatural ideal not intended for mortals but sounded pretty in a poetry book. Then, we met, and everything changed, the cynic has become the converted, the sceptic, an ardent zealot."
E.A. Bucchianeri, Brushstrokes of a Gadfly
http://www.goodreads.com/quotes/tag/falling-in-love
- "No one ever fell in love gracefully."
Connie Brockway, The Bridal Season
http://www.goodreads.com/quotes/tag/falling-in-love
- "Have you ever longed for someone so much, so deeply that you thought you would die? That your heart would just stop beating? I am longing now, but for whom I don't know. My whole body craves to be held. I am desperate to love and be loved. I want my mind to float into another's. I want to be set free from despair by the love I feel for another. I want to be physically part of someone else. I want to be joined. I want to be open and free to explore every part of them, as though I were exploring myself."
Tracey Emin, Strangeland
http://www.goodreads.com/quotes/tag/heartbroken 
- "Martin's dream is a vision not yet to be realized, a dream yet unfilled, and we have much to do before we can celebrate the dream as reality, as the suppression of voting rights and horrific violence...has so painfully demonstrated."
http://online.wsj.com/article/SB10001424127887324591204579039772530945520.html
- Love is more easily experienced than defined. As a theological virtue, by which we love God above all things and our neighbours as ourselves for his sake, it seems remote until we encounter it enfleshed, so to say, in the life of another - in acts of kindness, generosity and self-sacrifice. Love's the one thing that can never hurt anyone, although it may cost dearly. The paradox of love is that it is supremely free yet attaches us with bonds stronger than death. It cannot be bought or sold; there is nothing it cannot face; love is life's greatest blessing.
http://www.theguardian.com/commentisfree/2012/dec/13/what-is-love-five-theories

Written by Binh Nguyen

November 24th, 2014 at 4:18 am

Posted in memorable,quotes

Make Foresight to ask continue with update? [Y/n]

without comments

From scratch, you won’t get the question when installing/updating/removing applications. That need to be enabled in your system. It will assume you want to do the action and do it. To make it ask first, you need to open a file and add a setting for it. To do it, follow this guide:

sudo gedit /etc/conaryrc

Add this line on a new row:

interactive True

Save the file, now it will ask like you see below.

 

[tforsman@tforsman ~]$ sudo conary install chromium
[sudo] password for tforsman:
The following updates will be performed:
Install chromium(:rpm)=39.0.2171.65_1.el7.centos-1-1
continue with update? [Y/n]

 

Written by Tomas Forsman

November 24th, 2014 at 3:22 am

Posted in blog,Linux,News

Possible to download recipes – Foresighters repo

without comments

Iv’e been busy to find a way for users to see what’s been added to foresighters repo and able to download the recipe for the package. And now it’s possible.

First, you can see latest added recipes in the widget on the right side and browse all recipes here: https://www.foresightlinux.se/flr-recipes/

Don’t forget to look at Videos section, as Iv’e been planning to make some videos in the near future.

Wondered how Foresight Linux 7 looks like? Take a look at the video below.

Written by Tomas Forsman

November 23rd, 2014 at 3:29 pm

youtube-dl, Python video download tool, on front page of Hacker News

without comments


By Vasudev Ram



youtube-dl is a video download tool written in Python.

I had blogged about youtube-dl a while ago, here:

youtube-dl, a YouTube downloader in Python [1]

and again some days later, here:

How to download PyCon US 2013 videos for offline viewing using youtube-dl

(The comments on the above post give some better / easier ways to download the videos than I gave in the post.)

Today I saw that a Hacker News thread about youtube-dl was on the front page of Hacker News for at least part of the day (up to the time of writing this). The thread is here:

youtube-dl (on Hacker News)

I scanned the thread and saw many comments saying that the tool is good, what different users are using it for, many advanced tips on how to use it, etc. The original creator of youtube-dl, Ricardo Garcia, as well as a top contributor and the current maintainer (Filippo Valsorda and Philipp Hagemeister, respectively) also participated in the HN thread, as HN users rg3, FiloSottile and phihag_, respectively. I got to know from the thread that youtube-dl has many contributors, and that its source code is updated quite frequently (for changes in video site formats and other issues), both points which I did not know earlier. (I did know that you can use it to update itself, using the -U option).

Overall, the HN thread is a worthwhile read, IMO, for people interested in downloading videos for offline viewing. The thread had over 130 comments at the time of writing this post.

(On a personal note, since I first got to know about youtube-dl and downloaded it, I've been using it a fair amount to download videos every now and then, for offline viewing, and it has worked pretty well. There were only a few times when it gave an error saying the video could not be downloaded, and I am not sure whether it was due to a problem with the tool, or with the video site.)

[1] My first post about youtube-dl also had a brief overview of its code, which may be of interest to some Pythonistas.

This other post which mentions youtube-dl may also be of interest:

The most-watched Python repositories on Github

since youtube-dl was one of those most-watched repositories, at the time of writing that post.

- Vasudev Ram - Dancing Bison Enterprises

Signup for emails about new products from me.

Contact me for Python consulting and training.

Foresighters repo up and running for F7

without comments

We have created a foresighters repository for adding additional packages that don’t belong into main repository or in epel.

To be able to use all packages without thinking of specify the label, you can add a search line into system-model and add it in .conaryrc to make it work with conary rq ***

Written by Tomas Forsman

November 23rd, 2014 at 11:56 am

xzgrep for searching in compressed files

without comments

grep is a very powerful tool for everyone who works with text and strings. For searching through logs, errors and other text based data. But if the same data is present inside a compressed archive, like .bz2 or a .xz. Then we need to uncompress it and then use grep on the files.

If the number of such compressed files are too many, uncompressing all of them with out knowing which one contains the data that we are looking for could be a waste of time. This is were xzgrep can come to rescue.

xzgrep can search through compressed files of the formar .bz2,.xz etc and look for strings in the files like grep does. The only difference is that xzgrep can only confirm whether the search string is present in the compressed file or not and not be able to list further details like grep does.

For example let us take two files

hello1



hello2



Let us create a tar file



Compress it using bunzip



This will create the compressed file hello.tar.bz2

Now to search for text inside this compressed file.



The string 12 is present is hello1 thus the ouput says that a match is found.



If match is not found, xzgrep does not mention any thing.

But note that the xzgrep works only on the text files inside the compressed file, like grep works only on text files. Thus if the search string is inside a pdf or any other document, xzgrep will not be able to pick it up.


Written by Tux Think

November 23rd, 2014 at 6:46 am

Posted in Commands,Linux

Encrypt Everything: How to encrypt the disk to protect the data

without comments

Recently, at BrowserStack.com, some of our services got compromised. We use Amazon Web Services extensively. The person (or group) who attacked us mounted one of our backups and managed to steal some of the data. We could have prevented this simply by ensuring that we use encrypted disks which would have made this attack useless. Learning from our mistakes, we have recently started encrypting everything and I am going to show you how to do that. One point worth noting here is that Amazon AWS does provide encryption support for the EBS volumes but that is transparent and would not help in case of the account getting compromised. I am going to use dm-crypt which is supported by Linux kernel so the steps are quite generic and would work on any kind of disk, on any kind of environment, including Amazon AWS, Google Compute Engine, physical disks in your datacenter.

Our goal is to encrypt /home. To achieve this, we'll attach a disk, encrypt it, move the entire /home data to this disk and create a symbolic link to /home.

Step1: We are going to use Linux Unified Key Setup. For that we need to install cryptsetup package.
# yum install cryptsetup

Step2: While using AWS, never attach the volume to be encrypted while launching the instance. If we do so, the instance will fail to boot up next time because it'll ask for decryption password while booting up which is not possible to supply in AWS. Still if it is absolutely mandatory to do this then I suggest trying to remove entries from fstab and crypttab but it is much easier to just attach the disk after the launching of the instance is done. Assuming that the attached disk is available at /dev/xvdf, we'll setup the encryption now.
# cryptsetup -y -v luksFormat /dev/xvdf
WARNING!
========
This will overwrite data on /dev/xvdf irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:

Command successful.


We can verify the encryption parameters as well. Default is AES 256 bit.
# cryptsetup luksDump /dev/xvdf

Step3: We'll open the device and map it to /dev/mapper/home so that we can use it.
# cryptsetup luksOpen /dev/xvdf home
Enter passphrase for /dev/xvdf:


Step4: This step is optional. To further protect our data, we can zero out the entire disk before even creating the filesystem.
# dd if=/dev/zero of=/dev/mapper/home

Step5: Now we'll create a filesytem
# mkfs.ext4 /dev/mapper/home

Step6: Let us mount and copy the data from /home
# mkdir /myhome
# mount /dev/mapper/home /myhome
# cp -a /home/* /myhome/
# rm -rf /home
# ln -s /myhome /home

Great! Our /home directory is encrypted. But wait a minute.. this approach has a short coming. We have deliberately designed it so that the disk won't auto-mount during the boot because there is no way to give it a password in cloud environment during the boot. Since the disk won't mount, we won't be able to ssh into the machine because the authorized_keys file is kept inside the home directory of the user. To address this problem, either change the "AuthorizedKeysFile" in sshd_config or create a user with home directory in /var/lib or /opt and grant sudo for cryptsetup and mount commands. So after reboot, if we take the first approach, we would be able to ssh without any problem or we'll ssh via other user, mount the encrypted drive and then use it normally.

$ ssh mountuser@<ip>
$ sudo /sbin/cryptsetup luksOpen /dev/xvdf home
$ sudo /bin/mount /dev/mapper/home /myhome/


Couple of points to remember:
  • Do not forget the LUKS password. It cannot be retrieved, if lost.
  • Try it a couple of times on staging machines before doing it on the machines that matter.


Written by Aditya Patawari

November 22nd, 2014 at 1:39 pm

Based on Centos 7 – Possible to install now

without comments

Earlier we planned to use Fedora to build Foresight Linux upon. But some issues made it impossible to make that happen. So we will use Centos 7 as core and continue from there.

Now it’s possible to install centos 7 and get conary to work with it.

We have re-written the installation, so you can read how to install everything and get started.

Read more at: http://wiki.foresightlinux.se/index.php?title=Installation

 

Written by Tomas Forsman

November 22nd, 2014 at 1:37 am

Paramiko’s SFTPFile.truncate()

without comments

Paramiko is the go-to module for utilizing SSH/SFTP in Python.  One one the best features of Paramiko is being able to being able to SFTPClient.open() a remote file and simply use it like you would use a local file.  SFTPClient's open() returns an SFTPFile which is a file-like object that implements theoretically the same behavior as Python's native file object.
But the catch here is file-like.  It is like a file, except when it is not like a file.
The non-likeness I encountered concern's SFTPFile's truncate method.  The native Python file object has a truncate method where the size is option, if not specified it will default to the current offset of the file.  However SFTPClient's truncate method requires the size to be specified.  Failure to specify an size value results in a TypeError exception concerning incorrect number of parameters.

Written by whitemice

November 21st, 2014 at 8:49 am