Archive for the “'Techy” Category
Take a walk on the geek side.
25 Nov 2009 Answer by Sarah Vessels for What exactly does this Standard ML code do?
This doesn’t explain the whole thing, but note that in fun rotate($Nil, y::_, a), the y::_ is a pattern that matches a list wherein you label the head of the list (first element) as y and the tail of the list (every item after the first element) as _. _ acts as a wildcard pattern.
Check out SML on Wikipedia, specifically the Mergesort implementation, for more use of :: patterns and _.
25 Nov 2009 3:22 PM | Stack Overflow
25 Nov 2009 Answer by Sarah Vessels for Web service: PHP or Ruby on Rails or Python?
The first programming I ever did was with PHP, and it’s definitely very easy to get going with PHP on Dreamhost (I use Dreamhost for my PHP-based blog as well as Ruby on Rails project hosting). Ruby on Rails is pretty easy to get going on Dreamhost as well, now that they’ve started using Passenger. I learned Ruby and Ruby on Rails several years after I became comfortable in PHP and I prefer it to PHP because it feels much cleaner and I love the Model View Controller pattern for separation of code and content. I tried to learn Django after that but found myself frustrated because the meaning of “view” was different in Django than in Rails/MVC, so I didn’t get very far.
If you are doing quick-and-dirty, you might go with PHP. You could look into various frameworks for PHP, such as CakePHP or Symfony, for cleaner, more organized development. If you’re willing to spend more time learning (first for the language Ruby, then for the framework Ruby on Rails), you could go with Ruby on Rails. I really enjoy Rails development, but there was a learning curve since I learned both Ruby and Rails at the same time. There’s a lot of information out there about deploying Rails apps on Dreamhost.
25 Nov 2009 3:16 PM | Stack Overflow
23 Nov 2009 Answer by Sarah Vessels for CSS: two colums (fixed/fluid) – same height
I usually have two divs: the outer one would contain the sidebar content that I want to have the same height as the main column, and the inner div would be the main column.
-----------------------------
| -------------------- |
| | | |
| | | |
| | | |
| -------------------- |
-----------------------------
This way, the inner/main div forces the outer/sidebar div to be the same height as the inner/main. Just float:right the inner/main div, set the outer/sidebar div to be width:100%, and specify that the inner/main div has a left margin, to allow for the sidebar, e.g. margin-left:20%.
<div class="outer">
<div class="inner">
--main content--
</div>
--sidebar content--
</div>
Update: sorry, I had the sidebar content shown in the wrong place. It should be below the inner/main div so that the inner/main div shows up alongside it to the right when it is floated. Example CSS:
div.outer {
width: 100%;
}
div.inner {
margin-left: 20%; /* width of sidebar */
float: right;
}
23 Nov 2009 2:08 PM | Stack Overflow
18 Nov 2009 collapsing NULL values in Oracle query
I often write queries wherein I pivot data and end up with NULL values that I want to collapse. E.g. data like the following:
id time_in time_out
1 2009-11-01
1 2009-10-30
2 2008-12-15
2 2009-02-03
I then do an outer query like so:
SELECT id,
MIN(time_in) AS time_in,
MIN(time_out) AS time_out
FROM (...query above...)
GROUP BY id
This would produce data like this:
id time_in time_out
1 2009-10-30 2009-11-01
2 2008-12-15 2009-02-03
The problem is that I use a limited interface to access the Oracle database, and queries using MIN and MAX often time out. I was wondering if there is a more efficient way of “collapsing” NULL values than what I have done. Sometimes I GROUP BY another field that is not an index, whereas id shown above is a primary key.
18 Nov 2009 4:12 PM | Stack Overflow
18 Nov 2009 SELECTing user with earliest time and joining with other data
I have an Oracle database where I’m trying to select a user field from the earliest row (based on a time field) where certain conditions are met, and I don’t know how to do it. Here’s the gist of my query:
SELECT id,
CASE WHEN value = 'xyz'
THEN 'Pending'
ELSE 'Not Pending'
END AS status,
time
FROM table1
INNER JOIN ...
WHERE subject IN (...) AND
field = 'Status'
My problem is I don’t know how to SELECT user and get only the value from the row with the earliest time value matching the WHERE conditions. I don’t think I can use HAVING since I’m not doing any aggregate functions in my SELECT. The ‘earliest time value’ condition needs to apply only to the selection of the user field, i.e. I want id and value to be selected for all values of the time field.
I was thinking I could keep the SELECT statement I have above and then JOIN with another SELECT statement that gets the particular user I want.
SELECT id, status, time, user
FROM (
...query above...
),
(
SELECT user
FROM table1
WHERE subject in (...) AND
field = 'Status' AND
ROWNUM = 1
ORDER BY time ASC
)
However, this only gets one value for user overall, and there should be a separate user value for each id SELECTed in my first query. How do I limit my SELECT user query by the other query’s id field? Is this even the right approach to get what I want?
18 Nov 2009 2:13 PM | Stack Overflow
17 Nov 2009 Sims 3 World Adventures arrived
Whoo, The Sims 3: World Adventures arrived today! I had preordered it on EA’s site but was dubious about it 1) arriving the day it was released (i.e. today) and 2) actually being left on my doorstep/mailbox versus being stashed in some package center for me to go and pick up with my [...]
11 Nov 2009 Answer by Sarah Vessels for What’s your take on the programming language Go?
Reading “Go’s type system has no hierarchy, so no time is spent defining the relationships between types” (FAQ) sounds scary to me. Whether I go to statically typed C# or dynamically typed Ruby, I can have my classes and my inheritance and my interfaces/mixins. That’s how I think, and I don’t know how I’d do creating a large-scale application with no inheritance.
The lack of generic types and exceptions is also odd to me, and feels like a step backward (language design FAQ).
11 Nov 2009 11:04 AM | Stack Overflow
9 Nov 2009 C# abstract Dispose method
I have an abstract class that implements IDisposable, like so:
public abstract class ConnectionAccessor : IDisposable
{
public abstract void Dispose();
}
In Visual Studio 2008 Team System, I ran Code Analysis on my project and one of the warnings that came up was the following:
Microsoft.Design : Modify ‘ConnectionAccessor.Dispose()’ so that it calls Dispose(true), then calls GC.SuppressFinalize on the current object instance (’this’ or ‘Me’ in Visual Basic), and then returns.
Is it just being silly, telling me to modify the body of an abstract method, or should I do something further in any derived instance of Dispose?
9 Nov 2009 4:40 PM | Stack Overflow
9 Nov 2009 C# protected field to private, add property–why?
In Visual Studio 2008 Team System, I just ran Code Analysis (from the Analyze menu) on one of my C# projects. One of the warnings produced was the following:
Microsoft.Design : Because field ‘Connection._domain’ is visible outside of its declaring type, change its accessibility to private and add a property, with the same accessibility as the field has currently, to provide access to it.
It’s referring to the following field:
public abstract class Connection
{
protected string _domain;
}
I don’t understand the reasoning behind the suggestion. This is what I think it wants me to do:
public abstract class Connection
{
private string _domain;
protected string Domain { get { return _domain; } set { _domain = value; } }
}
Two questions:
- Did I understand correctly what the suggestion wants me to do, code-wise?
- Why does it want me to do this?
9 Nov 2009 4:02 PM | Stack Overflow
8 Nov 2009 PC hard drive dying
I don’t know if I blogged about it, but I certainly complained on Twitter about my Macbook hard drive eating itself at the beginning of the semester. Well, just this morning my Windows hard drive in my PC started acting up. When I booted the computer, I got a “DISK READ ERROR INSERT [...]