MUST DO
1. bake red velvet cake
2. study for the GRE (to take in August and in October if necessary)
3. take an anthropology class this fall
4. remember to send cards on time for each immediate family members' birthday, anniversary, mother's day, and father's day
TO DO
1. talk more to MJ... in Zhōngwén!*
*saying something cute is sometimes the only way to get him to correct me or talk back
2. sew more... pajama pants, skirts, etc
4. take winter yoga class
5. visit a friend living abroad
Thursday, July 8, 2010
Wednesday, July 7, 2010
I just got back from VT...
and that pretty much sums it up.
I'm reading Mountains Beyond Mountains. I'm at the part where Ophelia, with the inherent task in life of being Roald Dahl's daughter, is experiencing the fortune, and eventual misfortune, of falling in love with Paul Farmer.
Its the second book I've read in a really long time. Which makes me happy about my current state of affairs.
I suddenly got weirded out about being 26. Today I ordered the best crepe on the menu at Mr. Crepe, after 1.5 years of visiting Boston, and 1.5 of living in Boston (Fresh tomatoes with scallions and cilantro with brie). Then I also suddenly got weirded out by people leaving: some for a short while, some for good, some already gone. Maybe its empathy for getting left behind, because I've started feeling like maybe my time might be coming, too.
MJ: the 5 - 10 year travel list http://www.foreignpolicy.com/articles/2010/06/21/postcards_from_hell?page=full
MJ: but seriously
MJ: are there any countries that you'd rather see?
I'm reading Mountains Beyond Mountains. I'm at the part where Ophelia, with the inherent task in life of being Roald Dahl's daughter, is experiencing the fortune, and eventual misfortune, of falling in love with Paul Farmer.
Its the second book I've read in a really long time. Which makes me happy about my current state of affairs.
I suddenly got weirded out about being 26. Today I ordered the best crepe on the menu at Mr. Crepe, after 1.5 years of visiting Boston, and 1.5 of living in Boston (Fresh tomatoes with scallions and cilantro with brie). Then I also suddenly got weirded out by people leaving: some for a short while, some for good, some already gone. Maybe its empathy for getting left behind, because I've started feeling like maybe my time might be coming, too.
MJ: the 5 - 10 year travel list http://www.foreignpolicy.com/articles/2010/06/21/postcards_from_hell?page=full
MJ: but seriously
MJ: are there any countries that you'd rather see?
Wednesday, June 23, 2010
fixed my missing HTTP Response Content-Type Header in Firefox
And so I posted to the Aspose forums to help a brother out!
http://www.aspose.com/community/forums/245095/response.flush-clears-content-type-header-in-documentation-example-for-aspose.slides-for-.net-.sa/showthread.aspx#245095
"In IIS7 integrated pipeline mode, a call to Response.Flush causes the response to be sent without the content-type header unless a content-length has also been specified. In IIS6 or classic pipeline mode, the content-type header is sent as expected."
Posted by richard_deeming on 8/4/2009 at 7:44 AM
The issue appears to be in the internal HttpResponse.UpdateNativeResponse method:
if (((this._contentType != null) && this._contentTypeSet) && ((bufferedLength > 0L) || this._contentLengthSet))
{
HttpHeaderCollection headers = this.Headers as HttpHeaderCollection;
string str = this.AppendCharSetToContentType(this._contentType);
headers.Set("Content-Type", str);
this._contentTypeSet = false;
}
If the content length has not been set and no content has been generated, the content type header will not be sent.
In contrast, for IIS6 or classic pipeline mode, the WriteHeaders method calls GenerateResponseHeaders, which has:
if ((this._statusCode != 0xcc) && (this._contentType != null))
{
string str2 = this.AppendCharSetToContentType(this._contentType);
headers.Add(new HttpResponseHeader(12, str2));
}
Posted by Microsoft on 8/5/2009 at 2:55 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com/)
Posted by Microsoft on 8/6/2009 at 8:13 PM
Thanks for your feedback.
We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Thank you
Posted by Microsoft on 9/23/2009 at 10:16 AM
This issue will be fixed in the next major release of the ASP.NET and the .NET Framework.
Thank you for submitting this issue on Connect.
http://connect.microsoft.com/VisualStudio/feedback/details/480689/response-flush-clears-content-type-header
http://www.aspose.com/community/forums/245095/response.flush-clears-content-type-header-in-documentation-example-for-aspose.slides-for-.net-.sa/showthread.aspx#245095
"In IIS7 integrated pipeline mode, a call to Response.Flush causes the response to be sent without the content-type header unless a content-length has also been specified. In IIS6 or classic pipeline mode, the content-type header is sent as expected."
Posted by richard_deeming on 8/4/2009 at 7:44 AM
The issue appears to be in the internal HttpResponse.UpdateNativeResponse method:
if (((this._contentType != null) && this._contentTypeSet) && ((bufferedLength > 0L) || this._contentLengthSet))
{
HttpHeaderCollection headers = this.Headers as HttpHeaderCollection;
string str = this.AppendCharSetToContentType(this._contentType);
headers.Set("Content-Type", str);
this._contentTypeSet = false;
}
If the content length has not been set and no content has been generated, the content type header will not be sent.
In contrast, for IIS6 or classic pipeline mode, the WriteHeaders method calls GenerateResponseHeaders, which has:
if ((this._statusCode != 0xcc) && (this._contentType != null))
{
string str2 = this.AppendCharSetToContentType(this._contentType);
headers.Add(new HttpResponseHeader(12, str2));
}
Posted by Microsoft on 8/5/2009 at 2:55 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com/)
Posted by Microsoft on 8/6/2009 at 8:13 PM
Thanks for your feedback.
We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Thank you
Posted by Microsoft on 9/23/2009 at 10:16 AM
This issue will be fixed in the next major release of the ASP.NET and the .NET Framework.
Thank you for submitting this issue on Connect.
http://connect.microsoft.com/VisualStudio/feedback/details/480689/response-flush-clears-content-type-header
Friday, June 4, 2010
I just got back from India...
and that pretty much sums it up.
I'm reading Three Cups of Tea.
Its the first book I've read in a really long time. Which makes me both sad and happy about my current state of affairs.
I'm reading Three Cups of Tea.
Its the first book I've read in a really long time. Which makes me both sad and happy about my current state of affairs.
C# Dictionary, Hashtable, and HashSet
C# Data Structures: Dictionary, Hashtable, Set
Dictionary<>
The Dictionary C# data structure is extremely useful data structure since it allows the programmer to handle the index keys. What does that mean? Well an ArrayList automatically makes its "keys" integers that go up one by one, 1, 2, etc, so to access a value in an ArrayList one goes like: myArrayList[2];
So what the C# Dictionary data structure does is let us specify the keys, which can be any type of object. For example:
Retrieving a value is pretty straight forward:
Notice how convenient the Dictionary data structure is, in that there is no need to cast between types. Also there is nothing stopping you from creating a Dictionary like so:
That is a nested Dictionary C# data structure and it is fair game.
I understand that it can be confusing on how to go about getting all the values out of a Dictionary data structure since we have no way to knowing the pattern in the keys. Luckily we don't have to, here is the code to transverse a C#.Net Dictionary:
Hashtable
The C# Hashtable data structure is very much like the Dictionary data structure. A Hashtable also takes in a key/value pair, but it does so as generic objects as opposed to typed data.
Values are then stored in order according to their key's HashCode. Meaning that the order in which items are added to a C# Hashtable is not preserved. On the other hand, the Dictionary data structure does keep items in the same order.
The reason is speed. A C# Hashtable stores items faster than a C# Dictionary, which sacrifices speed for the sake of order..
(For those Java programmers, a Dictionary is more or less a TreeMap and a Hashtable is a HashMap).
HashSet
The HashSet data structure was introduced in C#.NET 3.5. This particular C# data structure very strongly resembles the List<> data strucuture.
So what is the difference? A HashSet has the very important characteristic that it does not allow duplicate values. For example:
If mySet were a regular List data structure, the index 2 should return the value 3 (count it out). But if you run the example you will see that myInt actually returns the value 10. This is because the HashSet C# data structure ignored the duplicate addition of the value 3.
You might wonder what is the point of this. After all, you could achieve the same behavior with a List data structure. Something like:
The result is indeed the same. But what is not apparent is the speed at which this happens. When an element is added to a HashSet, internally the same thing happens: the data structure makes sure the element doesn't already exist. However a HashSet is not a simple array, it is specifically designed to allow fast search times which dramatically improves the performace of checking whether a new element is a duplicate or not.
Dictionary<>
The Dictionary C# data structure is extremely useful data structure since it allows the programmer to handle the index keys. What does that mean? Well an ArrayList automatically makes its "keys" integers that go up one by one, 1, 2, etc, so to access a value in an ArrayList one goes like: myArrayList[2];
So what the C# Dictionary data structure does is let us specify the keys, which can be any type of object. For example:
Dictionary<string, int> myDictionary = new Dictionary<string, int>();
myDictionary.Add("one", 1);
myDictionary.Add("twenty", 20);
Retrieving a value is pretty straight forward:
int myInt = myDictionary["one"];
Notice how convenient the Dictionary data structure is, in that there is no need to cast between types. Also there is nothing stopping you from creating a Dictionary like so:
Dictionary<int, Dictionary<string, int>> nestedDictionary =
new Dictionary<int, Dictionary<string, int>>();
That is a nested Dictionary C# data structure and it is fair game.
I understand that it can be confusing on how to go about getting all the values out of a Dictionary data structure since we have no way to knowing the pattern in the keys. Luckily we don't have to, here is the code to transverse a C#.Net Dictionary:
//List<[same type as index]>
List<string> keyList = new List<string>(myDictionary.Keys);
for (int i = 0; i < keyList.Count; i++)
{
int myInt = myDictionary[keyList[i]];
}
Hashtable
The C# Hashtable data structure is very much like the Dictionary data structure. A Hashtable also takes in a key/value pair, but it does so as generic objects as opposed to typed data.
Values are then stored in order according to their key's HashCode. Meaning that the order in which items are added to a C# Hashtable is not preserved. On the other hand, the Dictionary data structure does keep items in the same order.
The reason is speed. A C# Hashtable stores items faster than a C# Dictionary, which sacrifices speed for the sake of order..
(For those Java programmers, a Dictionary is more or less a TreeMap and a Hashtable is a HashMap).
Hashtable myTable = new Hashtable();
HashSet
The HashSet data structure was introduced in C#.NET 3.5. This particular C# data structure very strongly resembles the List<> data strucuture.
So what is the difference? A HashSet has the very important characteristic that it does not allow duplicate values. For example:
HashSet<int> mySet = new HashSet<int>();
mySet.Add(3);
mySet.Add(5);
mySet.Add(3);
mySet.Add(10);
List<int> myListFromSet = mySet.ToList<int>();
int myInt = myListFromSet[2];
If mySet were a regular List data structure, the index 2 should return the value 3 (count it out). But if you run the example you will see that myInt actually returns the value 10. This is because the HashSet C# data structure ignored the duplicate addition of the value 3.
You might wonder what is the point of this. After all, you could achieve the same behavior with a List data structure. Something like:
if (!myList.Contains(element))
myList.Add(element);
The result is indeed the same. But what is not apparent is the speed at which this happens. When an element is added to a HashSet, internally the same thing happens: the data structure makes sure the element doesn't already exist. However a HashSet is not a simple array, it is specifically designed to allow fast search times which dramatically improves the performace of checking whether a new element is a duplicate or not.
Tuesday, May 11, 2010
to be read backwards
lol
SJM: Wait, is this the same guy who called you a firecracker?
LS: RP is the new guy who was at training yesterday.
HP: FYI - no idea what this means. Beware men with long ponytails.
RP: Yes and yes.
HP: Are you serious???? Can I tell Sue that? Is it the guy with the long ponytail?
RP: The trainer just called Sue a “wildcat” and a “wild mare”.
Awkward.
SJM: Wait, is this the same guy who called you a firecracker?
LS: RP is the new guy who was at training yesterday.
HP: FYI - no idea what this means. Beware men with long ponytails.
RP: Yes and yes.
HP: Are you serious???? Can I tell Sue that? Is it the guy with the long ponytail?
RP: The trainer just called Sue a “wildcat” and a “wild mare”.
Awkward.
Wednesday, May 5, 2010
JavaScript Sorting
Many of you are aware of the built-in sort function for sorting JavaScript arrays. But you might not realize the true power of this function. This tip will talk about how this built-in function can be used to sort multi-dimensional arrays.
If you have a one-dimensional JavaScript array, then calling the built-in sort method on the array will sort the array in ascending order. But what about the case where you have an array of first names, an array of last names, and an array of ages? You may want to sort the array of first names, but keep the corresponding positions in the last names and ages. This is done by setting up a multi-dimensional array and sorting the proper "column" of the multi-dimensional array.
First, setting up a multi-dimensional array is pretty easy. If you know the values ahead of time, they can be specified in your javascript code:
var myData = new Array();
myData[0] = {FirstName:"John", LastName:"Doe", Age:40};
myData[1] = {FirstName:"Fred", LastName:"Smith", Age:41};
and so on.
If you don't know the values ahead of time, then the easiest thing to do is to build a "constructor" function:
var myData = new Array();
function person(firstName, lastName, age) {
this.FirstName = firstName;
this.LastName = lastName;
this.Age = parseInt(parseFloat(age));
}
Then, to add a new entry to the array, it's just a matter of creating a new person object:
people[people.length++] = new person(form.FirstName.value, form.LastName.value, form.Age.value);
(The example has the values coming from user input on a form).
To sort the array, we need to tell JavaScript how to sort. This comes from a function that returns -1, 0, or +1 as a value. -1 will put the first value before the second in the sorted array, +1 will put the second value before the first, and 0 means the values are equal. For example, if we want to sort by the first names, here is a function that can be used:
function sortByFirstName(a, b) {
var x = a.FirstName.toLowerCase();
var y = b.FirstName.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
Two values are passed to this function. The values are array objects. If the first name part of the first object is alphabetically less than the second, -1 is returned. If the first name part of the first object is alphabetically greater than the second, +1 is returned. Otherwise, the first name values must be identical and 0 is returned.
But where does this function come in to play? There's an optional parameter to the built-in sort method that can be used. If you pass in a function name, that function name is used to compare elements in the array for sorting purposes. So, using this javascript call:
people.sort(sortByFirstName);
the array will be sorted in ascending order by the first name part of each array object. Similar functions and calls can be created to sort by the last name or by the age.
Note that JavaScript sorts in ascending order by default. But our function returns how things should be ordered. If we changed +1 to -1 in the function (and vice-versa) then the array would sort the first names in descending order. This is how you can sort by descending order.
JavaScript Sorting
If you have a one-dimensional JavaScript array, then calling the built-in sort method on the array will sort the array in ascending order. But what about the case where you have an array of first names, an array of last names, and an array of ages? You may want to sort the array of first names, but keep the corresponding positions in the last names and ages. This is done by setting up a multi-dimensional array and sorting the proper "column" of the multi-dimensional array.
First, setting up a multi-dimensional array is pretty easy. If you know the values ahead of time, they can be specified in your javascript code:
var myData = new Array();
myData[0] = {FirstName:"John", LastName:"Doe", Age:40};
myData[1] = {FirstName:"Fred", LastName:"Smith", Age:41};
and so on.
If you don't know the values ahead of time, then the easiest thing to do is to build a "constructor" function:
var myData = new Array();
function person(firstName, lastName, age) {
this.FirstName = firstName;
this.LastName = lastName;
this.Age = parseInt(parseFloat(age));
}
Then, to add a new entry to the array, it's just a matter of creating a new person object:
people[people.length++] = new person(form.FirstName.value, form.LastName.value, form.Age.value);
(The example has the values coming from user input on a form).
To sort the array, we need to tell JavaScript how to sort. This comes from a function that returns -1, 0, or +1 as a value. -1 will put the first value before the second in the sorted array, +1 will put the second value before the first, and 0 means the values are equal. For example, if we want to sort by the first names, here is a function that can be used:
function sortByFirstName(a, b) {
var x = a.FirstName.toLowerCase();
var y = b.FirstName.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
Two values are passed to this function. The values are array objects. If the first name part of the first object is alphabetically less than the second, -1 is returned. If the first name part of the first object is alphabetically greater than the second, +1 is returned. Otherwise, the first name values must be identical and 0 is returned.
But where does this function come in to play? There's an optional parameter to the built-in sort method that can be used. If you pass in a function name, that function name is used to compare elements in the array for sorting purposes. So, using this javascript call:
people.sort(sortByFirstName);
the array will be sorted in ascending order by the first name part of each array object. Similar functions and calls can be created to sort by the last name or by the age.
Note that JavaScript sorts in ascending order by default. But our function returns how things should be ordered. If we changed +1 to -1 in the function (and vice-versa) then the array would sort the first names in descending order. This is how you can sort by descending order.
JavaScript Sorting
Subscribe to:
Posts (Atom)