Switching to Mac

2014-01-27
I’ve recently switched from windows and linux to mac. Pretty much everything is different. Here are the shortcuts I can’t live without:
On Windows, I used to…On my Mac…
HomeCmd+Left
EndCmd+Right
Deletefn+Backspace
Ctrl+LeftAlt+Left
Ctrl+RightAlt+Right
Cut Ctrl+XCmd+X
Copy Ctrl+CCmd+C
Paste Ctrl+VCmd+V
PrintScreenCmd+Shift+3: print full screen to file on desktop
Cmd+Shift+4: print selected region to file on desktop
Cmd+Shift+4 Space Click: print selected window, including shadow, to file on desktop
Cmd+Ctrl+Shift+3: print full screen to clipboard
Cmd+Ctrl+Shift+4: print selected region to clipboard
Cmd+Ctrl+Shift+4 Space Click: print selected window, including shadow, to clipboard
Cmd+Space grab Cmd+Shift+W Click Click Cmd+S: print selected window, without shadow, to file
pipe |Alt+Shift+L
tilde ~Alt+N Space
Ctrl+Alt+Del Force quit unresponsive application Cmd+Alt+Esc Click
Cmd+Alt+Shift+Esc (hold for three seconds)
Ctrl+Shift+Esc Task ManagerCmd+Space Activity Monitor
F2 rename fileEnter
Windows+Leftinstall ShifIt and then Cmd+Alt+Ctrl+Left
Windows+Rightinstall ShifIt and then Cmd+Alt+Ctrl+Right
Del to delete a fileCmd+Backspace
Windows+D to show desktopfn+F11
Insert to select a file in midnight commanderCtrl+T

See also Apple Support: Switching PC Habits.

Optimizing JavaScript is harder than ever

2011-06-11

We’ve all got our favorite browser. And while developing for the web we test in that one browser first. Optimizing JavaScript for one browser only is a tempting idea. I mean … how much difference could there be between browser engines anyway?

Let’s use the Fibonacci sequence as an example. I wrote six different versions to calculate it. Obviously the naive, recursive way of calculating it is the slowest, but that is where similarities between browsers end. Internet explorer seems to be faster at looping than rounding numbers. And Chrome seems to favor local variables over global ones so much it doesn’t mind doing a lot more calculations.

Internet Explorer Platform Preview randomness is biased

2010-03-16

After installing Internet Explorer Platform Preview 1.9.7745.6019 the first thing I did was check out its javascript performance on my own scripts. It turns out to have a very wierd output for Math.random. Test your browsers Math.random() function and see for yourself.

Update: This seems to be fixed in Explorer Platform Preview 1.9.7766.6000.

Custom model binder to avoid decimal separator problems

2009-07-30

I bumped into an issue while trying to get the open source ASP.NET MVC project NerdDinner running on my laptop. The Create action in the DinnersController just wouldn’t work. This was due to Latitude and Longitude values being set with a different decimal separator than my server expected. It got "0.0" instead of "0,0" which the Double.parse function didn’t understand. A client-side JavaScript wrote these values into hidden fields, so it was a bit difficult for me to understand at first. I wrote a custom model binder to solve this for all fields of type double at once.

As I’m still learning ASP.NET MVC, my solution may not be the optimal one.

Read the rest of this entry »

IE8 aggressive caching fix

2009-03-20

Apparently Internet Explorer 8 has a more aggressive caching mechanism than any other browser I’ve ever met. To fix it I’ve added the following to almost every dynamic page on my server.

<%
// prevent caching (asp classic jscript)
Response.CacheControl = "no-cache";
Response.AddHeader("Pragma", "no-cache");
Response.Expires = -1;
%>
<%
' prevent caching (asp classic vbscript) '
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>
<?php
// prevent caching (php)
header('Cache-Control: no-cache');
header('Pragma: no-cache');
header('Expires: ' . gmdate(DATE_RFC1123, time()-1));
?>
// prevent caching (C#)
//Response.AddHeader("Cache-Control", "no-cache");
//Response.AddHeader("Pragma", "no-cache");
//Response.Expires = -1;

Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);

More information here: How to prevent caching in Internet Explorer

Silverlight vs Flash Chess

2009-03-16

After seeing the Silverlight Chess sample I immediately started work on a flash version. It needs a lot of optimizing, not a single variable type was set, so it’s not a very fair fight. Anyway … flash is about 10x faster than the ie7 js engine on my machine. But still a lot slower than silverlight.

Read the rest of this entry »

Generate Excel files in ASP Classic

2009-03-02

Generating Excel files in ASP Classic is not as easy as I thought. I hope someone finds use in this little piece of code that shows a way to export data to csv and to xls.

Read the rest of this entry »

Selecting a random employee with adjacency tables

2009-02-24

In my previous blogpost I mentioned a way to retrieve the entire tree from a hierarchy stored with adjacency tables. Now I’ve got a way to retrieve a random employee in an organisation.

I use ORDER BY NEWID() to randomize the order and TOP 1 to get only one result.

WITH Bosses (id, boss_id, name, depth, hierarchy)
AS (
	SELECT id
	, boss_id
	, name
	, 0
	, name
	FROM People
	WHERE boss_id IS NULL
	
	UNION ALL
	
	SELECT People.id
	, People.boss_id
	, People.name
	, Bosses.depth + 1
	, CONVERT(VARCHAR(50), Bosses.hierarchy + ' > ' + People.name)
	FROM People
	, Bosses
	WHERE People.boss_id = Bosses.id
)
SELECT TOP 1 * 
FROM Bosses
WHERE depth >= 2
ORDER BY NEWID();

Adjacency tables

2009-02-24

I’m well aware that adjacency tables aren’t the newest way of storing hierarchies in a database. Personally I prefer to use nested sets. But on this one project I had to work with a legacy database. It took me quite a while to find out how to retrieve an entire tree in one requests. This is obviously needed to speed up queries on large amounts of data.

This query is here to help me remember how to do it.

DROP TABLE People;

CREATE TABLE People (
id INT NOT NULL PRIMARY KEY IDENTITY
, boss_id INT
, name VARCHAR(50)
);

SET IDENTITY_INSERT People ON

INSERT INTO People (id, boss_id, name)
          SELECT 1, NULL, 'Bert'
UNION ALL SELECT 2, 1, 'Sylvie'
UNION ALL SELECT 3, 1, 'Sylvia'
UNION ALL SELECT 4, 2, 'Davy'
UNION ALL SELECT 5, 2, 'Xavier'
UNION ALL SELECT 6, 3, 'Kristof'
UNION ALL SELECT 7, 3, 'Piet';

WITH Bosses (id, boss_id, name, depth, hierarchy)
AS (
	SELECT id
	, boss_id
	, name
	, 0
	, name
	FROM People
	WHERE boss_id IS NULL
	
	UNION ALL
	
	SELECT People.id
	, People.boss_id
	, People.name
	, Bosses.depth + 1
	, CONVERT(VARCHAR(50), Bosses.hierarchy + ' > ' + People.name)
	FROM People
	, Bosses
	WHERE People.boss_id = Bosses.id
)
SELECT * 
FROM Bosses
ORDER BY Bosses.hierarchy;
idboss_idnamedepthhierarchy
1NULLBert0Bert
31Sylvia1Bert > Sylvia
63Kristof2Bert > Sylvia > Kristof
73Piet2Bert > Sylvia > Piet
21Sylvie1Bert > Sylvie
42Davy2Bert > Sylvie > Davy
52Xavier2Bert > Sylvie > Xavier

Css in Flex

2008-08-29

I had some issues today to change the background color of a button in Flex. The up-skin was set for the Button selector which meant setting the fill-colors property for the Button.special selector had no effect. Setting the up-skin to null was the only solution. This was easy to do in code with setStyle, but I wanted to do it in css. Writing null wasn’t quite enough. Apearently you need to use ClassReference(null). Hope this helps someone out.

Button {
  up-skin: Embed(source='img/example.png');
}
Button.special{
  up-skin: ClassReference(null);
  fill-alphas: 1.0, 1.0;
  fill-colors: #00FF00, #00FF00;
}