Archive for the ‘Tips’ Category

zip cmd line utilitiy snippet

Thursday, December 28th, 2006

This zips wp-admin and all its subdirectories into a file named test.zip.

>zip test.zip -r ./wp-admin/*

Use >unzip utility to unpack it.

One more cookbook for redirecting http to https in IIS

Friday, September 8th, 2006

First, credit to Michael at this site:

http://blog.opsan.com/archive/2005/04/17/395.aspx

ok, now for my cookbook description.
1.
to secure a whole website.
in iis mmc, properties of website, directory security, secure communications,
click the ‘Require secure channel, require 128-bit encryption’.

2.
now in c:\inetpub\wwwroot, make a nonssl directory in windows explorer.
now in iis mcc, make a virtual directory and point to the
c:\inetpub\wwwroot\nonssl directory.

3.
in iis mmc, right click the new virtual nonssl directory.
goto directory security, secure communications, and uncheck require secure channel.

4.
Drop a file named sslredirect.asp into this directory. Put the following script into it.

—————-
< %
If Request.ServerVariables("SERVER_PORT")=80 Then
Dim strQUERY_STRING
Dim strSecureURL
Dim strWork

' Get server variables
strQUERY_STRING = Request.ServerVariables("QUERY_STRING")

' Fix the query string:
strWork = Replace(strQUERY_STRING,"http","https")
strWork = Replace(strWork,"403;","")
strWork = Replace(strWork,"80","")

' Now, set the new, secure URL:
strSecureURL = strWork
'response.write(strSecureURL) ' uncomment for sanity check.
Response.Redirect strSecureURL
End If

%>
————

5.
Goto iis mmc website properties, custom errors, 403;4.
Switch it to URL and location of:
/nonssl/redirectssl.asp

6. done.

Some good resources:
http://blog.opsan.com/archive/2005/04/17/395.aspx?Pending=true
http://weblogs.asp.net/pwilson/archive/2004/12/23/331455.aspx

Tortoise CVS Move hack

Monday, August 21st, 2006

CVS doesn’t support moving files within a repository. (Great program, but didn’t get architected so well, eh? Programmers will want to move project files around in the future? Never happen!)

As you may know, a CVS ‘move’ means you have to Remove the directory structure and then Add it to the new place. (Deleting your history in the process.)

If you are using Tortoise CVS and you move a huge directory structure over, you may experience the hell of having 100’s of conflicting ‘hidden’ CVS directories throwing errors when you try to add the structure. You can write a script to remove them recursively or remove them by hand, but here’s a simpler hack for windows.

 (Always make a fresh backup before removing or moving lots of files in CVS!)
1. Run the Tortoise Remove command on your directory structure that you want to move. Commit the ‘remove’.
2. In Windows Explorer, move the leftover directory structure to someplace outside of the overal CVS directory hierarchy. This removes all the old hidden CVS directories that were left behind.
3.  Go to Windows Recycle Bin, and you will see all the
files that you removed from CVS using Tortoise. Order these by data deleted. Highlight them all and click ‘Restore’. This moves all those files and folders back into their old structure, but minus the hidden CVS directories.
4. In Windows explorer, copy your new ‘clean’ diretory structure to the desired location. Now click ‘Add Contents’ in Tortoise CVS from the top of that structure. Then click ‘Commit’.

5. You can now delete the old set of hidden CVS folders.

6. Always confirm your ‘Move’ by making a brand new download of the CVS repository, and building the app.

Final Thoughts:

- I think it would be great to build this functionality into Tortoise.
- Use Subversion instead of CVS every time you can. Subversion supports moves natively, is faster, uses less bandwidth, etc.

Wireless access point troubleshooting tip.

Tuesday, August 8th, 2006

Everything is fine with your wireless router or access point for years or months. Then one day it starts to drop connections every 2 hours or so for no apparent reason. The router doesn’t crash and the router doesn’t add an entry into its log when this happens. In fact, nothing has changed in your network. It just doesn’t work all the sudden.

There may be a new wireless device within range that has caused yours to malfunction. It could be the office or home next door. So, login to your router and move it to a new spot on the big three positions of the wireless router spectrum. 1, 6, or 11.
Give it some time and move it again if the first new position doesn’t clear up the dropped connections.

how to use stl random_shuffle with seed of your choice on a vector of pointers

Saturday, June 17th, 2006

I cannot understand why an example of this doesn’t show up anywhere in Google or Google Groups.

Hopefully, you found this page before you wasted as much time as I did searching.

A. Define a functor class like this one: (props to Midgaard, who almost had what I needed).[1]

class RandIntClass
{
public:
RandIntClass() {}
int operator() (int aRange)
{
srand(42);//seed of your choice here
int result = rand() % aRange;
return result;
}
};

B. In your code. Assuming you have a vector of pointers already.
//shuffle set 1 w/ seed 42

#include algorithm (add brackets around ‘algorithm’. wordpress keeps removing them for me.)
RandIntClass Rand;
std::random_shuffle( myVector.begin(), myVector.end(), Rand );

That should do it.
I tested this with two identical vectors. I shuffled each one independently, and they came out in the same order.

I have no idea why zero of the major stl tutorials out there couldn’t put this example together. I hate it when examples only use primitives or they only used the time(NULL) example.

Anyway, hope this helps. Enjoy,

Ed

If you are on gcc, watch out for this gotcha with srand48:

http://gcc.gnu.org/ml/libstdc++/2000-08/msg00015.html

[1] http://home20.inet.tele.dk/midgaard/tipc20050110.html

Configuring Visual Studio Unmanaged C++ Solution with Main Project and a Project to Test the Main Project

Tuesday, April 11th, 2006

So, this seemed basic, but no one appears to have written about it on the web.

You are in Unmanaged C++ solution in VS. You want a project, and then you want a second project that tests the first project.

Well, the test project will never be able to Link to the object files of the main project. Try it. The linker will complain.

The testing project needs its own copy of the main project’s .obj files.

1. Add every single file from the main project to the test project.

That’s right, you can’t just put the main project’s obj files in the test projects lib path. If you try to force it to link, it will crap out from duplicate symbols in the linker.

So, for each file in the main project, you need to click ‘Add > Existing Items” in the test project.

I made a separate folder in Visual Studio for my actual Testing files, so they wouldn’t get confusing. Note, folders in visual studio are not created on the windows explorer file system. They exist only in the view provided inside visual studio.
So, now there are 2 copies of every .obj file in the main project, one in each project’s intermediate directory.  However, there is still only one of each source .cpp and .hpp file. This is shared between the two projects, but these source files should reside in the main projects directory, not the test directory.

Personally, I’d like to be able to make the test project have Read-Only references to the main projects source files. Just so that I never accidentally edit the main project from th e source project. but oh well.
I suppose this makes sense, but I sure as hell never saw mention of this in any of the tutorials for creating unit tests for unmanaged c++ in Visual Studio.

Well, there went another 3 hours of my life to creating a proper build environment for c++. Wish I had 3 hours of unit testing instead.

If you’re reading this, hope it helps.

TortoiseSVN Tips (including how to skip typing your password a million times)

Tuesday, March 7th, 2006

Here’s the format for the address at SFSU (San Francisco State University). You cannot use the ~username shortcut, like you can in Apache. It must be the full path.
svn+ssh://ed@thecity.sfsu.edu/home/student/ed/projects/svn/hivm

You must use the svn + ssh combo. Just svn or just http will not work.
Also, here’s how you put the password into TortoiseSVN so it doesn’t ask you for it 3 times per update. (thus making you never want to check in). Unfortunately, this isn’t a flexible solution if you login to different SVN servers.

Settings > Network > SSH Client:
C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe -pw mypassword

Webdav: How to get MS WebDav to work in a LAN.

Tuesday, February 28th, 2006

You must use Network Places.
File > Open in IE (use web folders), will not work.

Server: Windows 2003 SP1, IIS 6, in Active Directory Domain
Clients: Windows XP SP2

Instructions:

My Network Place
Add Network Place
Next
Choose another network location
http://mycompany.dyndns.org:80/myfolder/ (uses open Internet)
or
http://sf-server-02.mydomain.local:80/myfolder/ (uses VPN tunnel)

put in username and password, and click ‘Save Password.’
May have to do this 2 times.

If your icon under ‘My Network Places’ has a folder with an Earth symbol on it, it probably worked.
If it has a folder with a piece of paper, then it failed.

————————–

http://mycompany.dyndns.org:80/myfolder/ PASSED

without trailing ‘/’ PASSED ( but why risk it.)

with local name. (use sf-server-02.mydomain.local instead) PASSED

without :80 (either local or internet name) FAILED

without dyndns.org or fully qualified domain name. (use sf-server-02 instead) FAILED

without a subfolder at all FAILED

—————–

Then test moving it back and forth. Does it work?
Yes. Cannot copy over a ‘locked’ file.
You can copy over an unlocked file, same as anywhere.

Netbios and WINS are disabled in this network.
Pure DNS network.

Linksys WET54G v3 Annoyances

Wednesday, January 25th, 2006

In Adhoc mode, two WET’s cannot use wpa security and connect to each other.
WPA only works in Infrastructure mode.
2 WET’s can only connect in ad-hoc mode.

Linksys refuses to post this information on their website.

Linksys refuses to give out the release notes for v1.08 of the firmware for the WET.

Awesome.

Part 2.

A WET54G v3 v1.08 firmware and a WRT54G v2 v4.20.7 firmware can only we connected using WPA1 TKIP for security (if you want WPA.)
This must be done in infrastructure mode.

I know this. Not one goddam stupid son of a bitch at Linksys tech support has access to this information. (until they read this blog.)

Awesome. I love Linksys. Cisco did a fucking great job transforming them from a shoddy company that makes half ass products with lousy support and terrible documentation. Keep it up!

One more note, there is a problem with using my domain’s dns suffix across the bridge. We don’t use netbios, just dns in the environment.

nslookup mycomputer.domainname.local fails
nslookup mycomputer succeeds.

Not sure why. Have to remap some drives b/c they had the suffix in their name. But it looks like this will work.