jr3 (63K)

One liners for linux, ruby and perl

Posted by Jessica Tue, 06 Feb 2007 01:53:00 GMT

One-liners

Posted by Jessica Sun, 07 Jan 2007 04:18:00 GMT

and Frequently used commands I can’t seem to remember the exact syntax of. Nothin’ fancy.

Linux
find . -name \*.* | xargs grep search_string

    navigate to folder you would like to search, enter this command with the search string you would like to find and this command lists all files containing that string
ps x -Ho pid,args
    lists all of the processes running
find / -name gcc
    finds all folders named gcc
sed '/$/,/' /home/Desktop/jessirae > /home/Desktop/jessirae2
    places a comma at the end of each line
paste -sd '\0' - /home/Desktop/jessirae2 > /home/Desktop/jessirae3
    The NEWLINE character of every line except the last line in each input file will be replaced with a separator

Ruby

"<a href=\"http://www.oldurl.com\">JessiRae.com</a>". gsub(/(http?:\/{2})\S+\.(\w+)(\S+)/,"http://www.jessirae.com/blog/")
    global substitution replaces all instances of some expression in a string with some other string or performs some function on that string
require 'open-uri' .... open(url) { |page| page_content = page.read() page_content }
    returns html from specified webpage

Google Sets + Sed = Quick Keywords for Meta Tags

Posted by Jessica Tue, 17 Oct 2006 20:32:00 GMT

I know there is alot of talk about search engine optimization. Additionally, I have no idea whether or not keywords in the meta tag do anything to help people find your site. With that said, I want to share how to quickly generate and format keywords for the meta tag.

To generate keywords for a website, go to Google Sets. Enter some small group of keywords that describes your site. For example, if I were maintaining a site on machine learning, I might enter the following terms: machine learning & artificial intelligence. This search returns 40 to 50 keywords related to machine learning.

Copy these keywords into a text file and delete any that aren’t relevant or that are misleading.

Now, if you were to simply cut and paste this list of keywords into your HTML document, your document would be UGLY (eew!) and difficult to read. Who wants to read a file with that many carriage returns?

The solution is to replace all end of line characters with commas (except the last EOL), so that things look relatively nice and neat in an html or rhtml or whatnot file.

To replace the end of line characters with commas, use the following two linux commands:

  • sed ’/$/,/’ file1 > file2
  • paste -sd ’\0’ – file2 > file3

You don’t have to create two extra files, but I do because often I have compiled keywords from several searches and wouldn’t want to repeat the process if I messed up the sed and paste commands. Besides after I have inserted the keywords into my html, I simply delete the files.

After getting all of the keywords on one line, paste them into the ”<META name=”keyword” content=””> statement.


UPDATE
For Windows users, there are two things I can recommend you do if you would like to use these commands.
    First, if you are running a website that is on a server running linux, you can ssh into the server, upload the text file you would like to convert (file1 in my example), and then run sed and paste on that text file.

    Second, you can try to run GNU Bash shell on Windows or install Cygwin. I haven’t tried either of these options because both my Windows laptop and desktop died (RIP my sweet babies) a few months ago.

designed by jowensbysandifer