May 18 2009

Google Query Syntax Explanations: Part 2

Here are a few more little known tricks that can be used to get better results from the google search engine. Save some bandwidth and tell your friends.

Operators
You can add all sorts of arguments to your google search query. The most useful that I’ve found so far is filetype. This allows you to specify the type of file that you want to search for.
If I type :
“iphone” filetype:pdf
into the google search engine then I only get pdf files in my search results, most of which are useful instructional manuals on the iphone.

There are many other arguments that can be useful:

intitle:”tech stuff”
inurl:”codytaylor”
intext:”iphone”
inanchor:”tech stuff”
site:codytaylor.org
link:www.codytaylor.org
cache:codytaylor.org
daterange:2452389-2452389
related:codytaylor.org
info:codytaylor.org
phonebook:”someone”

Stop Words

Google automatically removes certain words from searches. These are called stop words and consist of words like ‘I’, ‘a’, ‘the’, and ‘of’. To force google to use these words then add a ‘+’ to the begining of the word. So searching for a statement with ‘+the’ in it would force the query to look for the ‘the’. If you don’t care wheter these words are included in the search then why even enter them?

Order and repetition matter.

Searching
“codytaylor” scp
emphasizes the “codytaylor” and produces different results than searching
scp “codytaylor”
The keywords to the left are always given higher precedence in the query.

Searching
“codytaylor” scp
produces different results than searching
“codytaylor” scp scp

So if you’re looking for a page that is saturated with a specific keyword then you’ll have much more luck if you type it in more than once.

Share

May 17 2009

Google Query Syntax Explanations: Part 1

Basic Google Syntax Explanations

Ever see someone spending hours trying to find something in google and just giving up due to the enormous amount of content for any given keyword? I’m amazed at how little everyone knows about using the Google search engine. Most of the population uses google every day but are still unaware of  some very basic but extremely simple and effective syntax rules for google queries. This takes energy and bandwidth. In the following I try and outline two of the most common methods of narrowing your search results down to only what you want.

  • Basic Boolean: Use ‘AND’ and ‘OR’ in your query. The ‘AND’ will require the result to include both keywords and the ‘OR’ will allow results that have either keywords in them. You can also use the ‘|’ (pipe) character to specify ‘OR’. To make sure that none of the results include a specific word then use the ‘-‘ character in front of the word. So searching ‘cody AND taylor AND -yoyo’ will return results for cody taylor that do not include yoyo.
  • Quotes: Use quotes on a query to specify that you only want to search results that are exactly as you write them. If I google codytaylor most of my results are for cody taylor but if I google “codytaylor” then I get results only containing codytaylor without any spaces. Googles forethought in displaying results and splitting up words is very useful but a lot of the time you will want your results to be exactly as you specified. Quotes are also used to specify keyword order. If I wanted results for only the useful and not some sentence or combination of words that include those three words then I would specify “only the useful”. Try it and you’ll notice a huge difference. Try a couple queries to see how much more specific your results become.

These two basic features are surprisingly little known yet so straight forward. Save everyone some bandwidth and explain this to the people around you.

Yes, Google is a verb.

Check out Part 2

Share

May 17 2009

SSH Tunneling for Privacy and Trickery.

If you have access to a ssh server you can easily tunnel your web browsing and newsgroup/IRC activity to make sure that your IP is never associated with that ..stuff you do. You can basically tunnel any port through the any ssh server. These methods can be used to build up complex chains that are almost impossible to track.

To tunnel your basic browsing through a ssh “proxy” use this command:

ssh -D 8080 -p 22 codytaylor@someserver.com

I used port 8080 instead of the default 80 becuase I run a webserver on my local machine and I didn’t want to mess that up.

The -D in the command specifies a local dynamic application-level port forwarding which creates a socket to listen to the specified port on the local machine. Ancy connections made to this local port are forwarded over the secure channel.

This makes it easily possible to forward all web traffic on the local system through the secure channel by setting up a simple iptables rule:
–iptables -A PREROUTING -t nat -i eth0 -p tcp –dport 80 -j REDIRECT –to-port 8080

If you want to set up a secure ssh tunnel to connect to a specific newsgroup server you can use this command:

sudo ssh -N -p 22 codytaylo@sshserver.net -f -L 443:111.111.111.111:443

The -L specifies that the given port on the local client is to be forwarded to the given host and port on the remote side. This is basically a very specific instruction that tells all traffic that is directed to localhost at port 443 (119 if you don’t like double encryption) to go to the ip address 111.111.111.111:443. Note: I couldn’t get this to work with domains for some reason.

The -N tells ssh to not execute any remote commands. So you do not get the annoying ssh session stuff that makes you leave the terminal open.

The -f tells ssh to go into the background.

Share

May 15 2009

Read PDF’s Locally on the Iphone With Safari. No More Emails or URI Hacks

Read PDF’s Locally on the Iphone With Safari. No More Emails or URI Hacks

Essentially you can browse your entire iphone filesystem using this method but I just want to read PDF files as easily as possible.

I’ve been trying recently to find a proper PDF reader for the iphone that doesn’t really screw up the formatting or require very manual conversions and it seems that safari’s built in pdf reader is better than stanza and other readers.
Because safari on the iphone is not able to view files that are local on the device we need to do some quick work to make safari on the iphone read local files.
For this to work you will need to be able to access the iphone file system from a personal computer somehow. Check out how to get SCP on the iphone working.

First you will need to install the lighttpd program from cydia. It was under the networking section. Lighttpd is a tiny webserver for the iphone or ipod touch.
Once you’ve got lighttpd installed you will need to connect your iphone to your pc and open up SCP or a program similar over either wifi or through USB.

The version of lighttpd that I got from cydia didn’t have a default configuration file. So I created a file called lighttpd.conf which is extremely simple.
I chose not to put anything specific in the file because I never plan on accessing this iphone webserver from anywhere other than localhost.

server.document-root = “/var/www/”

server.port = 80

mimetype.assign = (
“.html” => “text/html”,
“.txt” => “text/plain”,
“.jpg” => “image/jpeg”,
“.png” => “image/png”
)

dir-listing.activate = “enable”

To check that your syntax is ok, log into the iphone with ssh or use a terminal app locally on the iphone and locate the lighttpd.conf file. I put mine in /etc.
Type this at the iphone prompt.

lighttpd -t -f lighttpd.conf

You should get “Syntax OK” after typing that into your iphone.

To start lighttpd:

lighttpd -D -f lighttpd.conf

Your document root on the iphone is now /var/www (if you used my configuration file) so start putting pdfs in there and you’ll now be able to read all those pirated ebooks that have been just sitting there taking up hard drive space for so long.
When you point safari to http://127.0.0.1/ you will now see a list of the pdfs (or whatever else you want to put in there).

Share

May 15 2009

Dojo Examples and Demos

The best resource for browsing all the features of dojo javascript is here. It not only displays all the features of dojo javascript but it also allows you to get any code for any feature you want. Check out here what you can do with it.

Share

May 2 2009

Apply CSS To Dojo Javascript for Profit with Cody Taylor

Cody Taylor writes:
My last dojo example wasn’t much for looking at and not very intuitive at all for the regular user. I highly doubt that anyone would pay me to integrate that into a custom web application. Most of the general public won’t think that a web page can include functionality like this. All the Dojo functionality was there for dragging and dropping but It didn’t really have the look and feel which is expected of Ajax web 2.0 applications so I decided to add a little CSS to pretty it all up and make it easier to use. First I’ll show the javascript for a basic list rearange application and then I’ll show the CSS that will make it look a lot more professional. For the impatient or rushed here is the example and code on one page.

So first the javascript :


dojo.require("dojo.dnd.Source");
dojo.require("dojo.dnd.Manager");

var c1;

function init(){
  c1 = new dojo.dnd.Source("container");
  c1.insertNodes(false, ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5","Item 6"]);
};
dojo.addOnLoad(init);

In the above javascript, which should be put in script tags in the header, there are a few simple things going on.
First it tells the dojo framework to include the drag and drop elements Source and Manager. These are very case sensitive and apparently used to be lower case in an older version of dojo.
Next the script declares a variable ‘c1’ and then defines the init() function. This init() function is where you want every dojo configuration option.
So it assigns c1 to a new Dojo Source called container. Next we insert 6 nodes into c1 with the insertNodes() function. The last line attaches this init() function onto Dojo’s Load event.
These few lines create a Drag and Drop basis for rearranging the 6 items we defined which will ba available on load.

Next The HTML :


<body>
<center>
  <h1 class="cody_title">Cody Taylor's Dojo Example</h1>
  <div id="dojo_list">
    <div style="margin:5px; ">
      <h3>Dojo List</h3>
      <p id="container" class="container"></p>
    </div>
    <div class="clear"></div>
  </div>
</center>
</body>

3 divs, 2 titles and a paragraph element. Important here are the id’s and classes. The id and class of the container paragraph tells Dojo that this is the source for dragging and dropping.

This is functional and all but it looks like basic text and no one will have any indication that it is in fact a drag and drop dojo web application. They will just think that the whole thing is broken. Here is an image of the bare application that I just outlined:

Now the CSS to pretty it all up:


body {
  padding: 1em;
  background:black;
  color:white;
} 
#container { width:400px; display:block; }
.clear { clear:both; }

To start with I put the background to black and the text to white and set a clear class to both left and right. Not really Dojo related but still relavent.


.dojoDndItemOver {
  background: #222222;
  cursor:move;
}

This sets the color of the DndItem when mousing over and changes the text select mouse cursor to a to indicate that you can move each element.


.dojoDndAvatar {
  border:2px solid #ccc;
  font-size: 75%;
  -moz-border-radius:8pt 8pt;
  radius:8pt;
}

This is the visual specification for the image that is displayed while dragging. The corners of the border don’t seem to work well in most versions of Internet Explorer but they look great in firefox.


.dojoDndAvatarHeader {
        display: none;
}

This to remove that header on the avatar that always seems to be “1” for me. If you want to keep that header just specify that dojoDndAvatarHeader has a back-ground color and remove the “diplay: none;”.


.dojoDndAvatarItem {
  background: #222;
  border-bottom:1px solid #666;
}

Just to make sure that the dojo avatar always has a proper background.


.dojoDndItemBefore {
  border-top: 2px solid orange;
}

.dojoDndItemAfter {
  border-bottom: 2px solid orange;
}

These two definitions really make this application easier to use. They basically indicate where the item that the user is dragging will go when dropped. This is very useful for showing the user how to use this application.


.container {
  border:3px solid #ccc; 
  padding: 1em 3em; 
  cursor: default;
  radius:8pt;
  background:#fff;
  -moz-border-radius:8pt 8pt;
}

This defines how the element containing the entire list will look.

Any suggestions on making this easier to use with visual cues would be greatly appreciated.
Cody Taylor.

Share

Apr 21 2009

64 Things Every Geek Should Know

If you consider yourself a geek, or aspire to the honor of geekhood, here’s an essential checklist of must-have geek skills.

1. The Meaning of Technical Acronyms
2. How to Reset RAM
3. Identify Keyloggers
4. Surf the Web Anonymously
5. Bypass a Computer Password on All Major Operating Systems
6. Find a Users IP Address on AIM
7. Hide a File Behind a JPEG
8. Crack a Wifi Password
9. Monitor Network Traffic
10. Recover Master Boot Record
11. Retrieve Data off Hard Drive
12. Load Rockbox onto an MP3 Player
13. Unbrick a Smartphone
14. Replace a Laptop Keyboard
15. Rip Streaming Videos
16. Strip Windows DRM
17. Homebrew Hack Game Systems
18. Find a Website IP Address Without Web/Command Prompt Access
19. Bypass School or Work Website Blocks
20. Screw with Wifi Leeches
21. Hexadecimal and Binary Number Systems
22. How to Hot Wire a Car
23. Increase Wifi Range
24. Carrying a Computer Cleaning Arsenal on Your USB Drive
25. Running an Operating System from a USB Thumb Drive
26. Understand What “There’s no Place Like 127.0.0.1” Means
27. Read 1337 At Normal Speed
28. At Least One Fictional Language
29. How to Survive in a Linux Argument
30. Identify Major Constellations
31. Use a Camera in Manual Mode
32. Who Mulder and Scully Are
33. Javascript
34. How to Unlock an iPhone
35. How to Install Mac OS X on a PC
36. Build a PC
37. Tethering a Smartphone
38. Wiring a Home Theater System
39. Replacing a Laptop LCD
40. Make a Laptop Cooling Pad
41. Unleash a Laser Pointer’s full potential
42. Keyboard Shortcuts
43. Soldering Glasses Together
44. How to Execute a Shell Script
45. How to Hack a Pop Machine
46. Turn a Laptop into a Digital Picture Frame
47. How to Mod a Flash Drive Case
48. Do Cool Things to Altoids Tins
49. Convert Cassette Tapes to Digital Audio Files
50. Lock Your Computer with a USB Drive
51. Run Your Own Ethernet Line
52. Set Up a Streaming Media Server
53. Setting up a VPN
54. Turn Webcams into Security Cameras
55. Control Your House Lights with a Computer
56. Play Retro Games without Retro Consoles
57. Put LEDs Inside a Lightbulb
58. Create Music with Keyboard
59. Make Your Office Ergonomic
60. Adding a Third Monitor
61. How to Convert a DVD to x264 (or XviD or DivX)
62. Flash System BIOS
63. How to Irrecoverably Protect Data
64. The Fastest way to Kill a Computer

Share

Apr 12 2009

INCREASE SEO with this mod_rewrite tutorial. Only the useful.

Since I didn’t really delve into how to actually use mod_rewrite to do something useful in my last post I will now.
The main reason I got mod_rewrite going is to improve my search ranking for a few sites so I’ll show how to do this with a dynamic php site.
What I primarily aimed at was to get $_GET variables to look like directories.

The .htaccess file from the previous post was


1. RewriteEngine on
2. RewriteRule ^/?test\.html$ test.php [L]

First line obviously turns on the .htaccess Rewrite Engine. .htaccess files can be used for other stuff. Check here for an example of a different use of a .htaccess file.

The second line is rewriting test.html to test.php. The text before the space represents the string to search and replace using regular expressions. The text after the space specifies what to replace the aforementioned string with.

This rule is really simple. The special characters that denote the regular expression are:

‘^’ This symbol, the caret, signifies the start of the URL.
This is under the current directory. Think of it like the ‘~’ character on the command line.
If your site is http://www.quick-content.com then
the ‘^’ in these regular expressions are the equivalent of the that URL
(as long as the htaccess file is in the root directory for that site).

‘$’ This symbol, the dollar sign, signifies the end of the URL.

“\.’ This is just a period. There is nothing special about this because it is ‘escaped’ by the slash.
For the search this will look just tell apache to treat it like a normal period.
This is necessary because the period has a special meaning and in this case we just
want to look for a period and not any character (which is the ‘.’s normal meaning).

It’s great and all to redirect from one file to another using mod_rewrite and apache but it’s not that helpful for SEO.
Here is another search and replace rewrite rule:


RewriteRule ^posts/([^/\.]+)\.html$ single_post.php?post_name=$1 [L]

This rule isn’t that simple.
First we want to match all urls that start with ‘posts/’.
Then we want to capture the characters that come after ‘post/’ but before ‘.html’ and use them as the get variable for the single_post php script.

This will rewrite pages like :
http://www.quick-content.com/posts/techstuff.html
to
http://www.quick-content.com/single_post?post_name=techstuff

The ‘()’ brackets tell apache to take whatever is inside of them and put it in a temporary location that can be acessed by the replacement string.
In this case the string ‘somepost’ is stored as $1. If you had multiple parenthesis then the $2,$3,.. would be used also.

The square brackets signify an expression of a sort. [0-9] will match any digit between 0 and 9. [^0-9] will match any character that is not between 0 and 9.
So [^/\.]+ matches one or more characters that are not a slash or a dot.

After that the ‘\.html$’ searches for the .html file extension so that url will look like a basic old html file.

A general overview of the structure of a mod_rewrite RewriteRule:


RewriteRule Pattern Substitution [OptionalFlags]

Fairly simple right? RewriteRules are dissected as follows:

RewriteRule
This is just the name of the command for apache.

Pattern
This is a regular expression which will be applied to the current URL.

Substitution
Substitution occurs in the same way as it does in Perl or PHP.

You can include backreferences and server variable names in the substitution. Backreferences to this RewriteRule should be written as $N, whereas backreferences to the previous RewriteCond should be written as %N.

A special substitution is -. This substitution tells Apache to not perform any substitution.

OptionalFlags

Any flags should be surrounded in square brackets and comma separated. The most useful are:

F – Forbidden. The user will receive a 403 error.
L – Last Rule. No more rules will be proccessed if this one was successful.
R[=code] – Redirect. The user’s web browser will be visibly redirected to the substituted URL.
If you use this flag, you must prefix the substitution with http://www.site.com/

There are more flags but I haven’t had a use for them yet.

I did up a few other more complex rewrites for one of my dynamic sites.


RewriteRule ^([0-9]+)/([0-9]+)/?$ /index.php?num_posts=$1&start=$2  [L]

This one is pretty straight-forward if you understood the previous example.
It is looking for two numerical strings separated by slashes. It then takes those two values and places them as the
$_GET[‘num_posts’] and $_GET[‘start’] variables. The ‘/?’ at the end allows for a possible slash.
[0-9]+ means: match one or more characters that are between 0 and 9.

The main problem that I ran into was that after a rewrite all of the images and includes would not work because I’m lazy and use relative paths.
So when I type a url like www.quick-content.com/10/11023/ I don’t get any images or style sheets because the browser is trying to find images
at www.quick-content.com/10/images/. I had to write two rules to make this work properly:


RewriteRule ^.*/?.+/images/(.+)$ /images/$1 [L]
RewriteRule ^.*/?.+/includes/(.+)$ /includes/$1 [L]

These rules check for one or more directories before the image or includes directory and if they exist then it rewrites the url to either /images or /includes.
The ‘.*/?’ means 0 or more characters before an optional slash (the ‘?’ following the slash means that it is optional).
‘.+/images/’ and ‘.+/includes/ tries to match one or more characters before the image or includes directory.
The ‘.’ means any character. So ‘.*’ means 0 or more any characters which is essentially any string.

Hopefully that wasn’t too confusing. There are a lot of great resources out there for learning regular expressions if you still don’t get it.
-Cody Taylor

Share

Apr 12 2009

Setting up mod_rewrite on ubuntu example. Only the useful.

mod_rewrite is a way to change one url to another. It is very useful for making dynamic php sites better for search engine optimization (SEO).

Obviously you’re going to need apache installed. I’m using Apache 2.0 with php5. This is how I did it.

I had hoped that it was already installed and I could just start writing regular expressions in an htaccess file and have everything work. So I went to check if it was installed by calling the phpinfo function. I created a file called asdf.php which contained:

I then did a search for rewrite in my browser. No go. So it’s either not installed or not enabled.
I checked the /etc/apache2 directory for any files that look like mod_rewrite.
I found rewrite.load in the mods-available directory. There is also a mods-enabled directory so I copied rewrite.load to mods-enabled with this command.


cody@taylor:/etc/apache2$: sudo cp rewrite.load ../mods-enabled/rewrite.load

I thought this may do it so I restarted apache2 with this command:


cody@taylor:/etc/apache2$: /etc/init.d/apache2 restart

I created two text files to test whether it was working:


filename: test.html
This is a HTML File

filename: test.php
This is a PHP File

I then created a .htaccess file in my web root directory which contained this text:


RewriteEngine on
RewriteRule ^/?test\.html$ test.php

I went to http://localhost/test.html hoping to see that it’s a php file. Didn’t work obviously.
I checked the sites-enabled directory and opened 000-default in vim.

It contained :

ServerAdmin webmaster@localhost
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ “/usr/share/doc/”
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128

AllowOverride is what I was looking for so I change AllowOverride to all and restart apache again.
This time when i check http://localhost/test.html I get that it is a php file which is good.

I noticed I was getting this error when I restarted apache:


cody@taylor:/etc/apache2$: sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

I fixed this by adding this line to the apache2.conf file:


ServerName "codytaylor.org"

A restart fixed it all up.

-Cody Taylor

Share

Mar 26 2009

Quick htpasswd Creation on Linux. Only The Useful.

Quick htpasswd Protection Setup On Linux.


cody@taylor:~$  <--This is the prompt. You do not need to type this

In the console get into the directory that you wish to protect.

cody@taylor:~$ cd /var/www/protected

Get the full path to the directory if you don’t already know it.


cody@taylor:~$ pwd

Create the htaccess file and add the following lines.


cody@taylor:~$ vim .htaccess
AuthUserFile /var/www/protected/.htpasswd
AuthName "This Site"
AuthType Basic
Require valid-user

Next use the htpasswd linux command which should be in the most common distros.


cody@taylor:~$ htpasswd -c .htpasswd someguy
New password: 
Re-type new password:

Almost done. Now you need to set the permissions on the files we just created.


cody@taylor:~$ chmod 755 .htaccess .htpasswd

All good.

Share