This post is intended as a self reminder.
To create a *.tar.gz file:
tar -czf filename.tar.gz dirpath
To extract a *.tar.gz file:
tar -xzf filename.tar.gz
Explanation of -czf:
c: create archive
z: pass the archive through gzip (to create .tar.gz vs .tar)
f: the following argument specifies the filename to use
Explanation of -xzf:
x: extract from archive
z: pass the archive through gunzip (to extract from .tar.gz vs .tar)
g: the following argument specifies the filename (the archive file) to use
Showing posts with label computers. Show all posts
Showing posts with label computers. Show all posts
Wednesday, March 3, 2010
Monday, February 22, 2010
Vim multiple commands in configuration file
I was struggling to come up with a means of mapping a keystroke to execute multiple Vim commands, within the .vimrc settings file.
Somewhere I read that to string multiple commands on one line, they must be separated with a | (pipe). That works inside of Vim, but causes errors when placed inside the configuration file.
Then I tried using :argdo, which also worked inside of Vim but not in the configuration file.
Finally I came upon a blog post which solved my problem. It appears that in the configuration file, pipes for separating commands must be escaped with a forward slash \.
I used to have a line in my configuration file:
noremap <silent> <C-h> :noh <CR>
This means that pushing Control-h would remove search highlighting.
Now it is:
noremap <silent> <C-h> :noh\| :set number!\| :set list! <CR>
The added commands toggle visibility of line numbers and whitespace. I like having those things visible, but I often need to copy text from vim to somewhere else and the line numbers and line-terminators get copied with it if they are displayed.
As for why I added these commands to an existing mapping: I am a vim novice and unaware of many vim shortcuts, so I decided not to accidentally overwrite any shortcuts. I figured that the existing Ctrl-h command was used rarely enough so that the annoyance of having to now push it twice for clearing highlighting (to negate the toggling produced by the first push) was an acceptable price to pay. And also one less shortcut to remember.
Somewhere I read that to string multiple commands on one line, they must be separated with a | (pipe). That works inside of Vim, but causes errors when placed inside the configuration file.
Then I tried using :argdo, which also worked inside of Vim but not in the configuration file.
Finally I came upon a blog post which solved my problem. It appears that in the configuration file, pipes for separating commands must be escaped with a forward slash \.
I used to have a line in my configuration file:
noremap <silent> <C-h> :noh <CR>
This means that pushing Control-h would remove search highlighting.
Now it is:
noremap <silent> <C-h> :noh\| :set number!\| :set list! <CR>
The added commands toggle visibility of line numbers and whitespace. I like having those things visible, but I often need to copy text from vim to somewhere else and the line numbers and line-terminators get copied with it if they are displayed.
As for why I added these commands to an existing mapping: I am a vim novice and unaware of many vim shortcuts, so I decided not to accidentally overwrite any shortcuts. I figured that the existing Ctrl-h command was used rarely enough so that the annoyance of having to now push it twice for clearing highlighting (to negate the toggling produced by the first push) was an acceptable price to pay. And also one less shortcut to remember.
Friday, June 5, 2009
RSS Addiction
Just last week I started using Google Reader. I had always seen the little orange symbols on blogs and webcomics, but I had never taken the time to figure them out. RSS? Atom? What? I hadn't felt a need to figure these out, and so I didn't bother.
I started reading webcomics a few years ago. It began with a single comic - xkcd. Once I had finished the xkcd archives and was at the point of waiting on updates, I was hungry for more. I found Questionable Content by Jeph Jacques (through Randall's "Comics I enjoy" paragraph at the bottom of his page), and Nothing Nice To Say by Mitch Clem (which I have no idea how I found). And when those archives were exhausted, I went on to find more comics. Fast forward to this summer, and I'm going crazy with the webcomics. My comic bookmarks have exploded to number more than 20, and I'm starting to forget which ones I have checked for updates and which ones I hadn't. Some of the comics update once a week, some twice a week, most three times a week, and others every day. And what if I accidentally missed an update! What then? Well, I would press the 'previous' button every time I checked for updates to make sure I hadn't missed any.
This process began to grow very tedious, and so I looked into something I had faintly heard of before - RSS readers. Satisfied with Google products, I checked out Google Reader. It was so easy to use! So simple to understand! I could drag and drop links from my bookmarks and there they would sit in my reader, just yearning to show off their updates to me. Gone were the days of trying to remember which comics were updated when, and gone were the worries of missing updates.
Unfortunately, this has recently grown into an addiction. Nowadays when I visit a webcomic or a weblog that I enjoy, or even just think I would enjoy, I'll add it to my reader. This creates a terrible feeling of hopelessness; I have 175 unread items, and they grow faster than I can read them. But that doesn't stop me from relentlessly hoarding more and more feeds. I mean, I could always unsubscribe if I wanted to.
I started reading webcomics a few years ago. It began with a single comic - xkcd. Once I had finished the xkcd archives and was at the point of waiting on updates, I was hungry for more. I found Questionable Content by Jeph Jacques (through Randall's "Comics I enjoy" paragraph at the bottom of his page), and Nothing Nice To Say by Mitch Clem (which I have no idea how I found). And when those archives were exhausted, I went on to find more comics. Fast forward to this summer, and I'm going crazy with the webcomics. My comic bookmarks have exploded to number more than 20, and I'm starting to forget which ones I have checked for updates and which ones I hadn't. Some of the comics update once a week, some twice a week, most three times a week, and others every day. And what if I accidentally missed an update! What then? Well, I would press the 'previous' button every time I checked for updates to make sure I hadn't missed any.
This process began to grow very tedious, and so I looked into something I had faintly heard of before - RSS readers. Satisfied with Google products, I checked out Google Reader. It was so easy to use! So simple to understand! I could drag and drop links from my bookmarks and there they would sit in my reader, just yearning to show off their updates to me. Gone were the days of trying to remember which comics were updated when, and gone were the worries of missing updates.
Unfortunately, this has recently grown into an addiction. Nowadays when I visit a webcomic or a weblog that I enjoy, or even just think I would enjoy, I'll add it to my reader. This creates a terrible feeling of hopelessness; I have 175 unread items, and they grow faster than I can read them. But that doesn't stop me from relentlessly hoarding more and more feeds. I mean, I could always unsubscribe if I wanted to.
Wednesday, April 22, 2009
More than meets the eye
I recently encountered a JPG image which appears as a picture in image viewers, internet browsers, and the like. However, opening it in WinRar reveals that it also encodes for a data archive.

One of the files in the archive is a text file containing instructions on how to create such an image/archive combination, along with a batch script that will do everything for you. Reading the contents of the batch script reveals that the combination is perfomed by using the "copy" command (I am a Windows user so I will refer to DOS commands) with not one but two source files - the jpeg and the rar archive. If the copy command sees more than one source file, it concatenates the data of all the source files, in their specified order, and outputs them to a destination file, or if a destination file is not specified it overwrites the contents of the first source file. The '/b' option must also be used with the copy command to specify that the data should be treated as binary rather than ASCII (since we are not dealing with text files).
It is important to specify the jpeg as the first file and the rar archive as the second, otherwise the image will not render. The reason is that jpeg encoding is broken up into a bunch of different chunks, each of which begins with a marker. The jpeg file starts with a Start of Image marker, and if that marker cannot be found at the beginning of the file (i.e. there is rar data before the jpeg data), then the image is "corrupt" and unable to be rendered. Likewise, the jpeg file ends with an End of Image marker, and disregards any data after it.
The rar file similarly begins with a header marker and ends with a ending marker. However, as I understand it, unlike how jpegs are interpreted, WinRar searches the entire file for the rar header marker, so this marker does not need to be located at the beginning of the file, which allows us to put the jpeg data there instead.So, when the file is opened in an image viewer, it sees the jpeg header at the beginning of the file and renders the jpeg image. When the file is opened in WinRar, WinRar searches and finds the rar header, and then displays the subsequent rar data.
This method of combination shoul also imply that more than just a jpeg file can be combined with a rar file - any other file should be able to be used instead of the jpeg, except for another rar file. And indeed, I was able to successfuly use a png image instead of a jpeg. Using a wav audio file instead of an image file was successful as well. When combining with an mp3, the rar archive was unable to be opened, and switching the order of the files made the mp3 unplayable. An avi file had the same problem as the mp3. When combining an mpg with a rar, the rar became unopenable, but switching up the order and combining the rar with the mpg let both files be openable/runnable. Realizing that this means that both an mpg and rar file can be the second source file in the combination made me consider attempting a triple combination. Would combining a jpeg with a rar and an mpg be successful? It sure is. Opening the file in the Windows Picture And Fax Viewer displayed the jpeg, opening with WinRar displayed the rar archive, and opening with Windows Media Player played the mpg.
I do not know the reasons that mp3's and avi's don't work, and why for a rar/mpg combination the rar must be the first source file. The assumption I would make is that the mp3 and avi have the same starting marker as the rar file, so when their data comes before the rar, WinRar finds the incorrect starting marker and fails to open an archive, and vice versa for when the rar data comes before the mp3/avi data. For the mpg, I would assume that the starting markers are distinct, but that the mpg data contains somewhere within it a marker that is the same as the rar's starting marker. In this way, when the mpg comes before the rar, WinRar finds the incorrect starting marker for the rar, yet when the rar comes before the mpg, the mpg starting marker is distinct and is not seen anywhere else in the file, so video players can open the mpg. Do keep in mind that these are mere speculations and not based on any research into the file structures.
Enjoy your newfound ability to hide files within files, and do keep in mind that a jpeg will look a little conspicuous if it is 30mb large.
One of the files in the archive is a text file containing instructions on how to create such an image/archive combination, along with a batch script that will do everything for you. Reading the contents of the batch script reveals that the combination is perfomed by using the "copy" command (I am a Windows user so I will refer to DOS commands) with not one but two source files - the jpeg and the rar archive. If the copy command sees more than one source file, it concatenates the data of all the source files, in their specified order, and outputs them to a destination file, or if a destination file is not specified it overwrites the contents of the first source file. The '/b' option must also be used with the copy command to specify that the data should be treated as binary rather than ASCII (since we are not dealing with text files).
It is important to specify the jpeg as the first file and the rar archive as the second, otherwise the image will not render. The reason is that jpeg encoding is broken up into a bunch of different chunks, each of which begins with a marker. The jpeg file starts with a Start of Image marker, and if that marker cannot be found at the beginning of the file (i.e. there is rar data before the jpeg data), then the image is "corrupt" and unable to be rendered. Likewise, the jpeg file ends with an End of Image marker, and disregards any data after it.
The rar file similarly begins with a header marker and ends with a ending marker. However, as I understand it, unlike how jpegs are interpreted, WinRar searches the entire file for the rar header marker, so this marker does not need to be located at the beginning of the file, which allows us to put the jpeg data there instead.So, when the file is opened in an image viewer, it sees the jpeg header at the beginning of the file and renders the jpeg image. When the file is opened in WinRar, WinRar searches and finds the rar header, and then displays the subsequent rar data.
This method of combination shoul also imply that more than just a jpeg file can be combined with a rar file - any other file should be able to be used instead of the jpeg, except for another rar file. And indeed, I was able to successfuly use a png image instead of a jpeg. Using a wav audio file instead of an image file was successful as well. When combining with an mp3, the rar archive was unable to be opened, and switching the order of the files made the mp3 unplayable. An avi file had the same problem as the mp3. When combining an mpg with a rar, the rar became unopenable, but switching up the order and combining the rar with the mpg let both files be openable/runnable. Realizing that this means that both an mpg and rar file can be the second source file in the combination made me consider attempting a triple combination. Would combining a jpeg with a rar and an mpg be successful? It sure is. Opening the file in the Windows Picture And Fax Viewer displayed the jpeg, opening with WinRar displayed the rar archive, and opening with Windows Media Player played the mpg.
I do not know the reasons that mp3's and avi's don't work, and why for a rar/mpg combination the rar must be the first source file. The assumption I would make is that the mp3 and avi have the same starting marker as the rar file, so when their data comes before the rar, WinRar finds the incorrect starting marker and fails to open an archive, and vice versa for when the rar data comes before the mp3/avi data. For the mpg, I would assume that the starting markers are distinct, but that the mpg data contains somewhere within it a marker that is the same as the rar's starting marker. In this way, when the mpg comes before the rar, WinRar finds the incorrect starting marker for the rar, yet when the rar comes before the mpg, the mpg starting marker is distinct and is not seen anywhere else in the file, so video players can open the mpg. Do keep in mind that these are mere speculations and not based on any research into the file structures.
Enjoy your newfound ability to hide files within files, and do keep in mind that a jpeg will look a little conspicuous if it is 30mb large.
Subscribe to:
Posts (Atom)