Andrew On Tech

tech tricks, hack, useful links, productivity tips, developers tools review and many more

Upgrade Rails on Mac

Posted by mymuss on November 17, 2008

First let’s check our version:


ruby -v
rails -v
gem -v

In my case the Rails version was outdated. Let’s upgrade it:


sudo gem update --system
sudo gem update rails --include-dependencies
sudo gem update rake --include-dependencies
sudo gem update sqlite3-ruby --include-dependencies
sudo gem install mongrel # ok, this one is optional, but still nice to have, when switching from rails 1 to rails 2

Posted in ruby | Tagged: | Leave a Comment »

sed one-liners

Posted by mymuss on July 28, 2008

… more sed one-liners:

http://student.northpark.edu/pemente/sed/sed1line.txt

Posted in *nix, Links | Tagged: | 2 Comments »

Multiline processing in sed

Posted by mymuss on July 28, 2008

You want sed to replace backslash-newline to space (i.e. to convert multiline string into a singleline) like this:


param =
     val1, \
     val2, \
     val3

should become


param = val1, val2, val3

The following sed command does the trick

sed -e :a -e '/\\$/N; s/\\\n/ /; ta'

Posted in *nix | Tagged: | Leave a Comment »

SQL Server 2005: XQuery snippets

Posted by mymuss on July 25, 2008

Suppose we have an XML snippet:

<root>
  <tag1>val1</tag1>
  <tag2>val2</tag2>
</root>

1. To get all pairs
tag1 => val1
tag2 => val2
etc.

DECLARE @x XML;
SET @x = '<root><tag1>...</root>';
SELECT
  CAST(C.query('local-name(.)') AS NVARCHAR(4000)) AS [Tag],
  CAST(C.value('.', 'nvarchar(4000)') AS NVARCHAR(4000)) AS [Val]
FROM @x.nodes('/root/*') T(C);

2. To insert a new pair where value is to be taken from a local variable:

DECLARE @val NVARCHAR(4000);
SET @val = 'val0';
SET @x.modify('insert <tag0>{sql:variable("@val")}</tag0> as first into(/root)[1]');

Note how sql:variable() function was taken into curly braces, otherwise it would have inserted ‘sql:variable(“@val”)’. Also the modify() argument must be a string literal, i.e. the following construction does not work: ‘insert ‘ + @val + ‘ as first into(/root)[1]‘

3. To update a value:

DECLARE @val NVARCHAR(4000);
SET @val = 'val000';
SET @x.modify('replace value of (/root/tag0/text())[1] with sql:variable("@val")');

No curly braces but still have to use sql:variable() function.

Posted in DB, Microsoft | Tagged: | Leave a Comment »

Syntax Sugar in SQL Server 2005

Posted by mymuss on July 25, 2008

1. Using OUTPUT clause:

DECLARE @NewKeys TABLE (
  [Key1]    UNIQUEIDENTIFIER NOT NULL,
  [Key2]    UNIQUEIDENTIFIER NOT NULL
);

UPDATE [XTable]
SET [Key2] = NEWID()
  OUTPUT inserted.[Key1], inserted.[Key2]
  INTO @NewKeys
WHERE [Key2] IS NULL;

Only updated rows go to @NewKeys table, of course a temporary or even a regular table can be used instead of table variable. No need for triggers.

2. Using JOIN with UPDATE:

UPDATE [x]
SET [x].[Key1] = [y].[Key1]
FROM [XTable] AS [x] INNER JOIN [YTable] AS [y]
ON [x].[Key2] = [y].[Key2]

Posted in DB, Microsoft | Tagged: | Leave a Comment »

SQL Server Management Studio: Vertical Split

Posted by mymuss on July 25, 2008

You can split a SQL Server Management Studio horizontally. Nice feature I didn’t know about.

Open at least two tabs and go to Window -> New Vertical Tab Group

Posted in DB, Microsoft | Tagged: , | Leave a Comment »

First post

Posted by mymuss on July 25, 2008

In this blog I will post various tips, tricks, hack that I found helpful. This is just a reminder for myself.

Posted in Uncategorized | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.