-
Recent Posts
Archives
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
Categories
Meta
Family Shot
Posted in Uncategorized
2 Comments
Doing a join in an update in SQL for PostgreSQL
Was writing some SQL queries for PostgreSQL for updating some tables and did a touch of trial and error for getting the syntax right for doing a join within an update statement. Below is how I did it. I’m thinking there should be a neater way.
update table1 set columnZ = newValue from table1 t1
inner join table2 t2
on t1.columnX = t2.columnY
where table1.uniqueID = t1.uniqueID
and t2.filterColumn = filterValue
Posted in Programming Tips and Tricks
Leave a comment
Recovered my dead / bricked acer aspire one
Had the Windows 7 Release Candidate on my Acer Aspire One, in the process of trying to reinstall XP from a USB key I ended up bricking my machine. Luckily I found the solution on this web page , my exact steps were:
I downloaded the latest BIOS from Acer Taiwan here here.
Freshly formatted a USB key to FAT32.
Copied the 3 files (3310.fd, flashit.exe, 3310.bat) to the USB key.
Renamed 3310.fd to ZG5IA32.fd, renamed 3310.bat to ZG5IA32.bat, and changed the contents of the batch file (ZG5IA32.bat) to point to ZG5IA32.fd
Put the USB key in the left side USB port
With the netbook off, held down FN+ESC, turned on laptop, released FN+ESC when the power light started flashing, pressed the power button once, and the USB key started flashing for about 1 minute and then the laptop rebooted. Fixed!
Posted in Uncategorized
1 Comment
How to show a Child Window from a Console window in C#
An amusing little example I came up with of how to open a window that is a child window of a console window. Just in case I need it in the future. Also useful for spawning a window from an OpenGL app, or hanging a child window off a separate thread.
// This is an example of how to open a Child Window from a Console
// Window in C#.
// By John Stewien 2010
using System;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ConsoleApplication {
/// <summary>
/// A simple form with a CheckBox that can be used to verify the
/// responsiveness of the Form.
/// </summary>
public class Form1 : Form {
public Form1() {
CheckBox checkBox1 = new System.Windows.Forms.CheckBox();
checkBox1.AutoSize = true;
checkBox1.Text = "Check / Uncheck to test responsiveness";
Controls.Add(checkBox1);
Text = "Form1";
}
}
class Program {
// Import the required Windows API functions
[DllImport("User32.dll", CharSet = CharSet.Auto)]
static extern IntPtr FindWindow(char[] lpClassName, char[] lpWindowName);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
static extern int SetWindowLongW(HandleRef hWnd, int nIndex, IntPtr dwNewLong);
const int GWLP_HWNDPARENT = -8;
// Store these parameters as statics as they are called from static methods
static IntPtr consoleHWnd;
static Form1 form;
/// <summary>
/// Method for running the form, called from a thread
/// </summary>
static void RunForm() {
form = new Form1();
SetWindowLongW(new HandleRef(form, form.Handle), GWLP_HWNDPARENT, consoleHWnd);
Application.Run(form);
}
// Delegate for invoking a method with no parameters
delegate void SimpleDelegate();
static void Main(string[] args) {
// Set the Console Title and then find its HWND
Console.Title = "Child Window On Console Test";
consoleHWnd = FindWindow("ConsoleWindowClass".ToCharArray(), Console.Title.ToCharArray());
// Run the Form
Thread thread = new Thread(new ThreadStart(RunForm));
thread.Start();
// Do some text stuff on the Console to show it is working
Console.WriteLine("Enter Text. Enter \"exit\" to exit.");
string text = "";
while (text != "exit")
text = Console.ReadLine();
// Close the Form so we can exit
form.Invoke(new SimpleDelegate(form.Close));
}
}
}
Posted in Uncategorized
Leave a comment
Getting Oz Solomon’s Project Line Counter to work in VS2008
I’m a big fan of Oz Solomon’s Project Line Counter from here http://www.wndtabs.com/, however there isn’t a version for Visual Studio 2008. I’ve got a work around though
Install the version for Visual Studio 2005, which fortunately installs even if Visual Studio 2005 isn’t present, then copy the following to notepad, save it and rename it to a .reg file, then double click it to enter it into the registry. After that, start VS2008 and you will see it there.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Addins\LineCount]
"FriendlyName"="Project Line Counter"
"AboutBoxDetails"="Project Line Counter Addin – Build 2.21.2.1024
Copyright (c) 1999-2006 by Oz Solomon
http://www.wndtabs.com"
"AboutBoxIcon"="C:\\Program Files\\WndTabs.com\\LineCount\\1033\\LineCountResources.dll,1"
"CommandLineSafe"=dword:00000000
"CommandPreload"=dword:00000001
"Descrption"="Counts lines of code in your projects"
"LoadBehavior"=dword:00000001
"SatelliteDllName"="LineCountResources.dll"
"SatelliteDllPath"="C:\\Program Files\\WndTabs.com\\LineCount\\"
Posted in Uncategorized
1 Comment
Taking a sunset photo with fill flash
I’ve recently acquired a new Canon 500D digital SLR camera, and I’ve been experimenting with different scenes. Some are trickier than others, e.g. to take a photo of my daughter with a sunset in the background required a bit of figuring out. Here’s one way of doing it:
1) Turn the mode dial to Aperture Priority
2) Set aperture to F stop 8.0
3) Set ISO to 200
4) Set exposure metering to spot metering
5) Set Auto Focus to One Shot
6) Close the built in flash
7) Point camera at daughter and half depress the shutter button to focus
While maintaining the shutter button in the half-depress (to hold the focus) do the following:
8) Point camera at the sky and press the Auto Exposure Lock button (AE button)
9) Press the flash release button to open the built in flash – this also changes the function AE button to a Flash measure button
10) Point camera at the whitest/brightest object in the foreground and press the AE button to fire off a pre-flash and set the flash strength
11) Repoint the camera at daughter and push the shutter button all the way down
One alternative is get up to step 9 by going full manual and setting up the exposure that way.
Posted in Uncategorized
Leave a comment
HttpListener Proxy
Just in case you find a use for some web proxy code…
I wrote a HttpListener proxy based on the HttpListener MSDN docs, and the web request code I did for something else. I had to do this because I needed to use the X-Plane updater from work which let me specify only an anonymous proxy, not the authenticated type that is at work. Here’s the code I got working for streaming binary data (note the HttpListener MSDN code only works for text as I discovered).
To test it I guess you could set a proxy in your web browser as 127.0.0.1:8080. The code below is the complete program.
using System;
using System.Net;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace HttpListenerProxy
{
class RequestData
{
public HttpWebRequest WebRequest;
public HttpListenerContext Context;
public RequestData(HttpWebRequest request, HttpListenerContext context)
{
WebRequest = request;
Context = context;
}
}
class Program
{
static void Main(string[] args)
{
// Create a listener.
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:8080/");
listener.Start();
try
{
while (true)
{
Console.WriteLine("Listening…");
// Note: The GetContext method blocks while waiting for a request.
HttpListenerContext context = listener.GetContext();
string requestString = context.Request.RawUrl;
Console.WriteLine("Got request for " + requestString);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestString);
request.KeepAlive = false;
request.Proxy.Credentials = CredentialCache.DefaultCredentials;
request.Timeout = 200000;
RequestData requestData = new RequestData(request, context);
IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(RespCallback), requestData);
}
}
catch (Exception e)
{
Console.WriteLine("\nMain Exception raised!");
Console.WriteLine("Source :{0} ", e.Source);
Console.WriteLine("Message :{0} ", e.Message);
}
listener.Stop();
}
static void RespCallback(IAsyncResult asynchronousResult)
{
try
{
// State of request is asynchronous.
RequestData requestData = (RequestData)asynchronousResult.AsyncState;
Console.WriteLine("Got back response from " + requestData.Context.Request.Url.AbsoluteUri);
using(HttpWebResponse response = (HttpWebResponse)requestData.WebRequest.EndGetResponse(asynchronousResult))
using (Stream receiveStream = response.GetResponseStream())
{
HttpListenerResponse responseOut = requestData.Context.Response;
// Need to get the length of the response before it can be forwarded on
responseOut.ContentLength64 = response.ContentLength;
int bytesCopied = CopyStream(receiveStream, responseOut.OutputStream);
responseOut.OutputStream.Close();
Console.WriteLine("Copied {0} bytes", bytesCopied);
}
}
catch (Exception e)
{
Console.WriteLine("\nMain Exception raised!");
Console.WriteLine("Source :{0} ", e.Source);
Console.WriteLine("Message :{0} ", e.Message);
}
}
public static int CopyStream(Stream input, Stream output)
{
byte[] buffer = new byte[32768];
int bytesWritten = 0;
while (true)
{
int read = input.Read(buffer, 0, buffer.Length);
if (read <= 0)
break;
output.Write(buffer, 0, read);
bytesWritten += read;
}
return bytesWritten;
}
}
}
Posted in Uncategorized
Leave a comment
