Sunday, January 26, 2014

Checking a url is valid, without downloading data.

I've had to do this a couple of times, check if images are available.
public static bool CheckWeblocation(string url)
		HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
		myRequest.Timeout = 300000;
		HttpStatusCode code = new HttpStatusCode();
                HttpWebResponse myResponse = null;
			myResponse = (HttpWebResponse)myRequest.GetResponse();
			code = myResponse.StatusCode;
			if (code != HttpStatusCode.OK)
				throw (new WebException("Status code is " + code.ToString()));
			return true;
		catch (WebException err)
			return false;        

Wednesday, December 12, 2012

Associate a file to a program via command line on Windows

assoc <extension>=<filetypename>
ftype <filetypename>=<programfullpath> %1 (%1 being the filename you are running)

assoc .ahk=autohotkey
ftype autohotkey=C:\hreinn\programs\autohotkey\autohotkey.exe %1

Thursday, November 8, 2012

Replacing content on clipboard in c#

Seems like a simple task, but there be dragons.

If you are running a multi-threaded program you have to move sideways.

I'm pasting (with little modifications) the answer from this stackoverflow article.

Exception threadEx = null;

System.Threading.Thread staThread = new System.Threading.Thread(new ThreadStart(
                            "PIXCHICKEN", //original name of the our company.


            catch (Exception ex)
                threadEx = ex;
        }), 0);
// at this point either you have clipboard data or an exception

Saturday, September 22, 2012

Just a quick note on NULL and "not in "

If you are using sql, you should be aware of this. This is very important.

If you want to update rows based on what values are not in another table.

If you use: "Update Chicken set Eggs = 0 where ChickenID  not in (select id from ChickTemp)"

And Chicktemp contains a single row that has id equal to null, "not in (Select id from ChickTemp)" will return no rows, you will reset the Eggs to zero for all entries in Chicken table.

Monday, September 3, 2012

Windows S3 tool modified for Greenqloud.

I found this tool on codeplex, - a standalone s3.exe file, allows you to upload multiple files at once.  I had some problems doing that on windows from s3cmd.

It's hardcoded to use only amazon servers, so I modified it for greenqloud, you can grab the version I made here,  or you can get the sourcecode, and just modify line 28 in Utils.cs to read

public static readonly string DEFAULT_SERVER = "";

I should probably submit a patch allowing you to modify it via settings, but to busy.

Please note that your access key / secret key is stored in cleartext under %\AppData\Local\s3\, you can opt for a password though.

Sunday, August 12, 2012

Upload images directly to Wordpress

We just implemented a direct upload from our cliphighres view (where you can select from custom sizes, maintaining aspect ratio - a cropped version of a highres) to Wordpress.

We have a couple of customers using Pixpuffin to manage their images and blogging to Wordpress and we just wanted to make life simpler for them, so now it's just at click of a button to upload the image.

We maintain the history of what images are uploaded to which blog (you can upload to more than one Wordpress site at a time).

Next step is indexing the text of the post they are attached to as keywords to make it easier to find.

We are actively looking into the more common used web systems to add similar functionality.

Facebook, Google+,Twitter and Blogger are next on the menu.  If you have a preference, please let us know.