Categories
Geeky/Programming

1729 – Saturday Night Programming before the bars: Natural Numbers…

Ok, so this afternoon I watched the movie “Proof” – really good movie. In the movie, they talk about the number 1729, about how it is the smallest number expressible as the sum of two cubes in two different ways. It also is a natural number – when its digits are added together, produces a sum which, when multiplied by its reversed self, yields the original number.

Just for the helluva it, I decided to write a little program in C# to do this. It would be nice if there was an easier way to reverse strings in .NET, maybe there is and I just don’t know. Anyways, I love how movies can get you into things you never thought you would get into.. now I only wonder what I will code up when I get back from the bars..

using System;
using System.Collections.Generic;
using System.Text;

namespace NaturalNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            // when its digits are added together, produces a sum which,
            // when multiplied by its reversed self, yields the original number:

            for (System.UInt64 i = 1; i < 9223372036854775808; i++)
            {
                string nums = i.ToString();

                System.UInt64 sum = 0;
                System.UInt64 product = 0;

                // get the sum of each digit of the number
                for (int b = 0; b < nums.Length; b++)
                {
                    sum += System.Convert.ToUInt64(nums[b].ToString());
                }

                string nums2 = sum.ToString();

                // reverse the sum
                char[] temp = nums2.ToCharArray();
                Array.Reverse(temp);
                nums2 = new string(temp);

                // multiply the sum times the reversed sum
                product = sum * System.Convert.ToUInt64(nums2);

                // if they equal we hit the jackpot
                if (product == i)
                {
                    Console.WriteLine(i.ToString() + " is a natural number");
                }

                if (i % 10000000 == 0)
                {
                    Console.WriteLine(i.ToString());
                }
            }
        }
    }
}
 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Technorati tags: , , , ,
Categories
Geeky/Programming

Unprotected Wi-Fi: Encrypt your traffic with an SSH SOCKS Proxy to Browse Securely

Unprotected Wi-Fi: The bastion of coffee shops, airports everywhere. Browsing on these hot spots is basically like having unprotected sex with the Internet. My new solution:

image

Just kidding. Anyways, if you do browse on an unprotected hotspot, it is very easy for anyone to see all your web traffic, your passwords, your email, basically everything you do. They can save this info, then go home and get into all your accounts, basically take over your life if you give away the right info. You don’t want that do you?

Now, when I decided to finally get secure, I did some research, looking on Google, I figured someone had already done this and documented it well. The best and most comprehensive thing I found was on Lifehacker with an article in their “Geek To Live” series. Now I went through these steps, and I had some issues getting things working. I followed their steps to the letter, but it still didn’t work. I am on Windows Vista, which in the comments of the article, looks like other people had issues as well. We will get to that later 🙂

The Lifehacker article has you use Cygwin for all the SSH stuff. Pretty much this is what doesn’t work on Vista, at least from my conclusions. Over the last week or so I have been working with network guru Chris Super (my loyal tester) to get this whole setup working, and he came to the same conclusion. So, what do you do when Cygwin doesn’t work and you are running Vista? Well there are some other tools you can use to get this all running smooth. And a side note, Cygwin – ugh, why don’t you have an uninstaller? So 1996….

Step 1: SSH Server

First you are going to have to set up a SSH server. I have a Vista box at home sitting under the TV, the perfect candidate. Instead of Cygwin and configuring stuff with a command prompt, you can install a cool looking GUI SSH Server, freeSSHd – this program really is cool. First, they are using components from WeOnlyDo software, which I have used before in some of the .NET networking tools I have written. Second, they make this really easy to set up and configure. You install it, add a user (NT auth or regular), set some options for tunneling and access and you are set. If you have issues with this step I can help you out, but the options are pretty self explanatory. One thing I found is that when you add a new user, you need to restart the service for the user to work. One other thing I did was run my SSH server on a different port than the default (22) as people just try to hack this port all day. Pick something way up in the list 22822 for example.

Step 2: Dynamic DNS

The second step, unless you are running in a datacenter, is to make it so you don’t have to connect to your IP address. Instead, we want a cool domain name. What I used for this is Dynamic DNS. Chris actually blogged about this a while ago, which reminded me of the service. They have come a long way since they first started, which is nice. What you do is sign up for their service, and then install their updater tool on the same computer or another computer on your internal network. How this tool works is it checks on an interval your remote IP and updates the Dynamic DNS service. Pretty cool. Now you can remember a human readable domain name instead of your IP address!

Step 2.5: Configure your Home Router

Now that you have your SSH Server running, and your domain name pointing at your cable modem, you want to configure your router. Most if not all routers have a way to forward ports to internal IP Addresses. What you want to do is allow the port you configured in step 1 (22822) to forward to the internal IP address of your SSH Server box. That way, when you do requests to your SSH server from outside your internal network, the traffic will go to the correct box. Save your settings and you are good to go.

Step 3: SSH Client

Here is another place where Lifehacker’s steps didn’t work for me, because of Vista again. Cygwin really doesn’t work worth a damn on Vista it seems. A really good SSH Client that works on Vista is Putty. There isn’t even an install, it is just an exe. Awesome. Basically what I did was create a batch file to run putty with the command line options I wanted. The major caveat to get this to work is you need to run putty as an admin. I have that already set up on my box so no issue, but you might need to run a cmd prompt as administrator to get this to work!

One line in the batch file:

putty -D 9999 -P <the port you configured from step 1>-l <login name you configured in step 1> -ssh <your domain name from step 2>

Replace the pieces in <> with your values. The 9999 in the command is the local port that your client applications will connect to, which then gets forwarded out to your SSH server through your domain name. We will get to that in Step 3.

Once you run putty, it should ask you to login with the password you created in step 1, and you are good to go. You need to have tunnel set up for your user in the SSH Server. You might have SFTP and Shell also set up, so you will see putty show you a command line. This is the command line on the actual server on your internal network! You should now be connected to your SSH server, but yet, you still aren’t secure, because no applications are set up to use the new proxy yet.

Step 3: Configure Client Applications

Now you can configure your applications on your laptop to use your new proxy. The major applications you need to configure are your Internet Browsers. Firefox and Internet Explorer.

In Firefox, go to Tools->Options: Advanced Tab, Network Tab, Settings Button. Check the radio button for “Manual Proxy Configuration”. in the SOCKS Host area put localhost (you might need to put 127.0.0.1) and then the port you configured in step 1.

In Internet Explorer (7.0), go to Tools->Options: Connections Tab, LAN Settings Button. Check the box to “Use a proxy server for your LAN…”, click the Advanced button, in the Socks area, put localhost and the the port you configured in step 1

Wow, tons of steps to just change a little setting! I have been playing with a way to automatically set these up based on your local IP Address but haven’t perfected it yet. Once I do, I will post up an easier way.

Other applications you might have on your machine are email, IM, etc. As far as email, you might want to use a web mail client at this point. Also, for IM, you can configure them all to use SOCKS, but when I am the coffee shop I use a web based IM like Meebo because since your Internet session in your browser is already secure because you configured your SOCKS settings in your browsers, your IM’s will also be secure. There are a few other applications that you might use, like Windows Live Writer, etc and they usually have a place to set up SOCKS settings. If an application doesn’t have a place to set up SOCKS, then you probably don’t want to use it.

If you do have a corporate VPN client, you can connect to that as it is secure, and then connect to corporate sites internally and email, etc. Usually corporate networks
have tunnel’s set up when you connect to VPN. All your “corporate” traffic will go down the secure tunnel, while other traffic (such as IM, Browsing, etc) will go down an unsecured tunnel. Now that you have your SSH server set up, basically you have 3 tunnels if you connect to VPN. Secure Corporate, Secure Public, and Unsecured Public (for the applications you can’t configure SOCKS for)

Step 4: Browse Securely

Now that you have your secure setup, you can browse with more confidence. You still need to be careful, but your traffic is pretty much unreadable my would be hackers. I tested this by running it on an XP Virtual Machine, while running Wireshark on my Vista box and all the traffic was unreadable.

 Once you get back home though, you need to reverse all the SOCKS settings in your client applications so you can browse again from your internal network. That is unless you want to connect to SSH from your internal network, but that is just overkill and bad performance.

As far as connection speeds, some people really complain that is slow. I haven’t really noticed. It is a bit slower, but I would rather it be a little slower and secure than fast and wide open. For casual browsing, reading feeds news, etc, it is fine.

Other Stuff:

I set up all this using a Vista box for the backend server and a Vista box for the client. In our testing we found that you need to run Putty as an administrator for it to work. I actually downloaded Ubuntu Linux 7.04 as a VMWare image, loaded up VMWare player and tested using the built in SSH client and that worked fine, so I knew my SSH Server was working. Also, I tested using a Windows XP SP2 VPC Image using Cygwin as the SSH client and it worked fine as well. So remember, if you are on Vista, you need Putty and you need to run it as an administrator!!

Since I have only been running this for around two days, there are still some bugs to be worked out. Every so often you might receive an error from Putty about an abnormal packet received. It basically disconnects you. You probably are fine since your client applications are still configured to use the proxy, so if you try to browse you will get an error, you need to shutdown Putty, and then reconnect to your SSH server, then you can browse just fine again.

I have tested this on Unsecured networks at local coffee shops, and as I write this blog post, I am sitting at Starbucks, connected to T-Mobile hotspot, securely tunneling through SSH to my server in my apartment, browsing securely – just need to login to the hotspot first, then connect to SSH, and change your client application settings.

Technorati tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Categories
Geeky/Programming Life Ramblings

IT Disaster Recovery, what the I-35W Bridge Collapse shows us

Now, I am from Minnesota originally. I drove over that bridge 3 days before it collapsed. It sucks, its a bad thing for the state, for the people involved, and for everyone who passed or is injured. It is a very sad situation that no one should have to go through.

What does the bridge collapsing have to do with IT? Well. It is a disaster. And like IT disaster scenarios, it gets the same “Oh my god we need to fix this” after the fact treatment.

MN Gov. Pawlenty announced an immediate emergency round of inspections of all of the state’s bridges, starting with the three that have the same structure as the crumbled Minneapolis span. Other Gov’s are having their bridges inspected in their states. People are running around going crazy about inspecting bridges that 3 days ago they could care less about. – What gives?

Really? Lets do something after the fact. The bottom line is that these kind of action plans should have been set up beforehand. Just like in IT. Backups is a good example. No one says or does anything or wants to spend any money on backups. Then one day, the server crashes and everyone loses their files and email. I will bet money the next day there is a huge budget and people running around like idiots getting a backup plan in action.

Where were those people before hand? We know that stuff needs to be backed up. We know that bridges need to be inspected. WTF are we doing? If we know the possible problems, and we know how we can prevent them, then why do we let things slide. Where is the accountability?

The government needs to step up. People that are leaders/decision makers need to step up. And if something does go awry, they need to take responsibility for what happened. Wether it is a bridge that fell, or a server that crashed, or any other disaster scenario.

Technorati tags: , , , , , , , , ,
Categories
Blogging Geeky/Programming Life

Travel, Trips, and Family: How Technology Plays A Major Role

After traveling this week, it has become really more apparent that technology plays a major role in the whole traveling process, as well as family interaction. Now I know there are the old schooler’s out there that will be like, phhh, you don’t need technology to do anything. I am not saying that, I am just saying it can make it easier, maybe a little better. Also, there are some things that bring people together (think of a Grandfather and Grandson fixing a car) – well, these same type of things are now the norm, but over technology (replace car with computer or cell phone – and the Grandson teaching the Grandfather).

Over the last 10 days or so, this is what I have seen.

MySpace: First, I hate MySpace. But tons of people are on it, and you can reconnect with old friends and people you know. A while back an ex-girlfriend of mine who I haven’t talked to in like 10 years contacted me on MySpace. We started talking, emailing, IM’ing, and then last weekend we went out for a beer and around, which was odd, but good. Thing is, this probably would never happened without MySpace.

Facebook: Same as MySpace – just different groups of people. Easy to update your status of what you are doing, plus message friends and plan things. I used this to find out about some people being out one night that I wanted to see, and ended up seeing them. Another thing, people find out when you break up with someone if you have that set on Facebook, which leads to people talking to you, asking you to hang, etc. Also, my boss and I figured out that Nickelback was playing because of iLike, on a day I was in town, and we decided to go. Which leads to the next thing…

Craigslist: To get the tickets for the concert, he used Craigslist. We ended up getting floor tickets, for cheap. We saw some people at the show we knew, and they paid almost double.

Twitter: here is a great one. As you are doing things, tweet it, and your friends can know what’s going on. Adds to your “Life Stream”. I used this to track cool things that were happening, as well as keep up on friends back in Portland, and other tech tweets (I knew what was going on at the TechCrunch party in CA from tweets and twittergrams).

Digital Cameras: No brainer here. Taking picture of cool things on a trip. Using your cell phone or a regular camera, either way, you can get cool photos, which then you can upload to..

Flickr/Picasa Web Albums, et al: Good way to show your pictures off to friends and family.

Online Flight Check In: I used this twice, the way out, and back. Print off your boarding pass, choose your seats. Pretty easy and saves some time at the airport.

Maps and Locations: Use this to get to the airport, and around. local.live.com though – you know how I feel about Google maps.

Texts/Texting: – another no brainer. Text your friends and family instead of calling.

Instant Messaging: another good thing, especially if you can do it from your phone, or reply to text’s to someone’s IM (AOL and MSN allow this). just another way to keep in touch and plan things

Cell Phones: – wikipedia, emails, photos, videos – you can use cell phones these days to do a ton. Look up stuff on wikipedia, get directions, movie times, its your contacts and calendar, alarm clock – everything

Laptops: – need this for traveling. Get on wifi spots, VPN into work, check your email, read blogs, etc.

Helping family technology wise – ok here is how the family fits in. Every time I come home, everyone in my family has some new computer or cell phone or something they can’t figure out and I end up helping, which leads to conversation, bonding, getting together, going out after (let’s go get some beer), etc. My grandpa got a new Sony Ericsson walkman phone and needed some guidance getting it going for example.

Online family tree – started this on Geni.com about a month ago. Reconnect with family, figure out what is going on, before you go home.

Scheduling/Calendars: if you use outlook, or any other online calendar you can access, then good. You can really maximize your time using calendars, and get alerts on upcoming appointments, etc/

YouTube: upload your Nickelback videos, duh! (I do have some of a great acapella group I saw in St. Cloud too!)

Blogs: you can also write to your blog to keep people in the loop. Track your flight, and just know you are OK once you land. BTW, I am on NWA 597 on the way back if you want to track me!

I am sure there is a ton more, but this is a good starting list. I figure this post is also a good way to give some details into what I did on the trip. I obviously did more, but its a good start. I will post up some pictures/videos once I get back to PDX (I am in the MSP airport right now, drinking a beer :))

Technorati tags: , , , , , , , , , , , , , , , , , , , , ,
Categories
Blogging Geeky/Programming Life

Portland Blogger Dinner

Tonight I walked on down the block to the Portland Blogger Dinner at Jive Software. Pretty cool. Jive is nice, Wii, 360, beer on tap in the break room… the work on a product called ClearSpace – collaboration software written in Java.

It was a good get together, met some cool people. I added some pictures up on flickr as well

Whiteboard Blogging

http://www.flickr.com/photos/scaleovenstove/sets/72157600915176106/

Some bigger bloggers where there, Jeremiah Owyang and Robert Scoble, and Josh Bancroft from Intel, all very nice people. Good times, can’t wait till the next one!

Of course, the topics of the night were Facebook, Twitter, and the iPhone…

Technorati tags: , , , , , , , , , , ,
Categories
Geeky/Programming SQLServerPedia Syndication

SQL Server: SELECT Current Database Name

As a short follow up to a post I did a little while ago on SELECT’ing the instance and machine names from SQL Server, here is how you get the Current Database Name

SELECT db_name()

Funny because I was looking for that online, and my Google search led me to my past blog post, so I figured I would actually blog about this specific function as well.

Technorati tags: , , , , ,
Categories
Geeky/Programming Product Reviews

iPhone. iDontGetIt

The iPhone. Ok, I finally got to play with one – thanks Mickey. It is pretty cool, but still. Windows Mobile can do everything plus more than the iPhone can, so why aren’t the fanboi’s wetting themselves over Windows Mobile devices? Why aren’t companies like SmugMug, 37Signals, Digg, etc making specific versions just for Windows Mobile? Windows Mobile has been out for many many years. It can do portrait, and landscape. It can do video, music, and maps. It can do SMS, email, web, photos, GPS (via Bluetooth) and more. Why isn’t anyone doing anything about that? What is so great about the iPhone? Because really, you have to use iTunes? iTunes blows. It really does. I swear it has to be the most poorly developed application out there for Windows, with Quicktime a close second (Ballman back me up here) 

It is funny when all of sudden, all these people are discovering you can actually do things on your mobile phone, where Windows Mobile users have know this for years. The biggest difference is that I can develop an application in an afternoon using the .NET compact framework for my Windows Mobile, that actually INSTALLS on the device, and has access to EVERYTHING (file system, registry, innards of the OS – and if I go the C++ route, even more so!). On the iPhone I can make a web app – whoo hoo! Big deal, there are tons of web pages that I can access on my Windows Mobile device. And with sites like T9Space.com, I can get them to render, somewhat well.

One other HUGE dealbreaker here is this: I can hook my Windows Mobile device up to my laptop, and boom – I have a modem. Can you do that with the iPhone?

I listened to the naysayers before it came out. The flip-floppers.  What were they thinking? 2 year contract? at&t – the worst of the worst. But they say “its an iPod” – wait a minute, iPods sucks too…why? because you have to (unless you are uber geek) sync them with iTunes!!! Oh wait – its multitouch!! – ok, that is about the only thing it has going for it. That isn’t something so groundbreaking that I am going to switch from my T-Mobile Dash smartphone for.

I just wish companies/developers would realize that there is a huge market out there for Windows Mobile – why don’t you develop specific apps just for that? Why why why! I ask you??!?! The iPhone is $300 a sale more into Apple’s bank account, for no real reason. It is locked down. It is like a TV that will only play CSPAN. Come on guys, open up to Windows Mobile. I usually tell people – ask me what I CAN’T do on my Windows Mobile device. I haven’t found a good answer to that yet.

Why would all these tech enthusiasts, total geeks, etc, totally be in love with a device which is just crippled, and not open? It is just limited in so many ways, I just don’t get it.

iAmStillNotConvinced.

Technorati tags: , , , , , , , , , , , , , , , , , ,
Categories
Geeky/Programming

How the f*#k! do I hibernate in Windows Vista??

Ok, so today was at Starbucks, and wanted to move on down the road, so I wanted to hibernate. To no avail, no option to hibernate my laptop in the shutdown area. Just sleep, shutdown, restart.

After 10 minutes of F’n around, I figured it out. Turn off “Allow Hybrid Sleep” in the advanced power settings in the power settings in control panel. Wow – that’s exactly where I would expect to turn it on!

Start->Control Panel. In the search I typed “hib” and an option to “Turn hibernation on or off” under Power Options comes up. Click on that. Then there is a link “Change advanced power settings”, click on that. Dig through the settings until you find the “Allow Hybrid Sleep” under the Sleep option.

hybrid_sleep

Nothing like making an option to actually turn on or off hibernation…man.

Technorati tags: , , , , , , , ,
Categories
Geeky/Programming

T-Mobile Hotspot and OpenDNS – They Hate Each Other (And how to mend the relationship)

Whenever I go to Starbucks to work, I connect to T-Mobile hotspot, since it is included with my phone plan. Cool right? Well, not really. At home I have Comcast, whose DNS really really sucks. So I used OpenDNS, which rocks, and never has issues.

Thing is, because T-Mobile hotspot uses DNS to verify you and make you login through their “intranet” page, you can’t use OpenDNS, so I have to go switch my DNS Settings every time I want to connect, that is no good, gotta be an easier way right? Oh there is…dug into “netsh” (I tested this on Windows Vista)

Create two batch files:

————————————–

Set DNS Dynamic.bat

netsh interface ip set dns “Wireless Network Connection” dhcp

————————————–
and then…

————————————–

Set DNS OpenDNS.bat

netsh interface ip set dns “Wireless Network Connection” static 208.67.222.222
netsh interface ip add dns “Wireless Network Connection” 208.67.220.220 index=2

————————————–

this assumes that your wifi connection in your network connection is named “Wireless Network Connection”. Run the Set DNS Dynamic when you are at Starbucks, run the other one when you get home. Easy!

I find this really helpful because in Vista, to get to your network properties for TCP/IP is like 18 steps/clicks, which is really a debacle when you just want to get on the Internet at a coffee shop!

Technorati tags: , , , , , , , , , , , ,
Categories
Blogging Geeky/Programming

Cool Blog Trick: Crosspost WordPress to MSN Spaces

I use MSN Windows Live Messenger as my main IM client, I have most of the people I IM with on there, all my contacts in my mail.live account, it syncs with my T-Mobile Dash running Windows Mobile 6.0, etc. But, as you can see, I am using WordPress instead of MSN Spaces (Windows Live Spaces) or whatever they are calling it these days (they change the names of this stuff like monthly, I swear).

Anyway’s, in Windows Live Messenger, when a contact updates their space, you will see on your contact list in Messenger a little yellow star next to their name and you can go to their updated space/blogs/photos, whatever.

I wanted this to happen for me, but I don’t want to use MSN Spaces. Did some digging and found a WordPress plugin that will do it all for me – cool!

You can find the plugin here: http://privism.org/blog/live-sync/

There were a few tweaks, I had to modify the PHP so that the sync all would work with WP 2.0, and also the sync all timed out once, so I had to re-run, but it picked up from where it left off.

Now, anytime I post here, it will cross post to my space: http://stevienova.spaces.live.com  and people that are on my Windows Live Messenger list will see that I updated it. Just another way to get your updates out to people who might not know what RSS is, or a Feed Reader, etc.

Technorati tags: , , , , , , ,