create login username with password = 'password'; (on master)
create user username for login username; (on database)
exec sp_addrolemember 'db_owner', 'username'
Saturday, July 21, 2012
Saturday, July 14, 2012
Longest Increasing Sequence C#
static public int LongestIncreasingSeq(int[] s) {
int[] l = new int[s.Length]; // DP table for max length[i]
int[] p = new int[s.Length]; // DP table for predeccesor[i]
int max = int.MinValue;
l[0] = 1;
for (int i=0; i<s.Length; i++)
p[i] = -1;
for (int i = 1; i < s.Length; i++)
{
l[i] = 1;
for (int j = 0; j < i; j++)
{
if (s[j] < s[i] && l[j] + 1 > l[i])
{
l[i] = l[j] + 1;
p[i] = j;
if (l[i] > max)
max = l[i];
}
}
}
return max;
}
Linear Partition in C#
static public void partition(int[] s, int n, int k) {
Console.Write("{");
Utils.printArray(s);
Console.WriteLine("}");
int MAXN = s.Length;
int MAXK = 3;
int[,] m = new int[MAXN, MAXK]; // DP table for values.
int[,] d = new int[MAXN, MAXK]; // DP table for dividers.
int[] p = new int[MAXN]; // prefix sums array.
int cost;
p[0] = s[0];
for (int i = 1; i < n; i++) p[i] = p[i - 1] + s[i];
for (int i = 0; i < n; i++) m[i, 0] = p[i];
for (int j = 0; j < k; j++) m[0, j] = s[0];
for (int i = 1; i < n; i++)
for (int j = 1; j < k; j++)
{
m[i, j] = int.MaxValue;
for (int x = 0; x <= (i - 1); x++)
{
cost = Math.Max(m[x, j - 1], p[i] - p[x]);
if (m[i, j] > cost)
{
m[i, j] = cost;
d[i, j] = x + 1;
}
}
}
Console.Write("{");
reconstruct_particion(s, d, n, k);
Console.Write("} ");
}
private static void reconstruct_particion(int[] s, int[,] d, int n, int k)
{
if (k == 1)
{
print_books(s, 0, n);
}
else
{
reconstruct_particion(s, d, d[n - 1, k - 1], k - 1);
print_books(s, d[n - 1, k - 1], n);
}
}
private static void print_books(int[] s, int start, int end)
{
Console.Write("{");
for (int i = start; i < end; i++)
Console.Write(" {0} ", s[i]);
Console.Write("} ");
}
Thursday, June 28, 2012
There is a known issue in the WCF Services SDK which may soon cause you at least a really annoying message; "this operation is not supported for a relative uri". While it is not fatal and you can ignore it – as a matter of good coding, I tend to get rid of as many warning messages as possible. To fix it, open your machine.config (both x86 and x64 version), and delete the following section:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
<endpoint address="" binding="netTcpRelayBinding"
contract="IMetadataExchange" name="sb" />
Wednesday, January 18, 2012
Presenting Storyboard View Controllers Programmatically
Although the storyboard runtime usually handles transitions between view controllers, you can also trigger segues programmatically from your code. You might do so when setting up the segue in Interface Builder is not possible, such as when using accelerometer events to trigger the transition. There are several options for transitioning to a new view controller:
- If a storyboard file contains an existing segue between the current view controller and the destination view controller (perhaps triggered by some other control in the view controller), you can trigger that segue programmatically using the
performSegueWithIdentifier:sender:method ofUIViewController. - If there is no segue between the view controllers but the destination view controller is defined in the storyboard file, first load the view controller programmatically using the
instantiateViewControllerWithIdentifier:method ofUIStoryboard. Then present the view controller using any of the existing programmatic means, such as by pushing it on a navigation stack. - If the destination view controller is not in the storyboard file, create it programmatically and present it as described in View Controller Programming Guide for iOS.
Friday, December 16, 2011
iphone element sizes
Core Elements:
Carrier Status bar - 320x20
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44
Data Input:
UIPickerView - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216
Buttons:
UISegmentedControl - 320x44
UIButton xx37
UIButton xx37
Fields:
UITextField - xx37
UISwitch 94x27
UISlider - xx23
UISwitch 94x27
UISlider - xx23
Indicators:
UIProgressView -xx9
UIActivityIndicatorView - 37x37
UIPageControl - 38x36
UIActivityIndicatorView - 37x37
UIPageControl - 38x36
Thursday, August 4, 2011
UIEdgeInsets.
Shrinking, Expanding, Edge Insetting
If you need to shrink a CGRect by a certain value horizontally and vertically you could do so by modifying the structure members themselves. But way more elegant is to use the provided convenient macro CGRectInset. Positive values will decrease the size evenly for the new rectangle to be centered in the old one. Negative values by the same token will increase it.
CGRect aRectangle = CGRectMake(0,0, 100, 200); CGRect smallerRectangle = CGRectInset(aRectangle, 10, 20); // result origin (10, 20) and size (80, 160) |
This method is fine for 80% of use cases, but sometimes you want to apply different insets for each edge. Imagine, if you will that you want, to have a property contentInsets that would specify the distance a view content should have from each border. The structure of choice for this is UIEdgeInsets(top, left, bottom, right), and of course, there is also a matching Make macro available.
Once you have both you can easily apply the insets to your rect to receive the finally content rectangle. The macro for this purpose is UIEdgeInsetsInsetRect, would you have guessed?
CGRect rect = CGRectMake(0, 0, 100, 200); UIEdgeInsets contentInsets = UIEdgeInsetsMake(10, 20, 30, 40); CGRect result = UIEdgeInsetsInsetRect(rect, contentInsets); NSLog(@"x: %f, y: %f, width: %f, height: %f", result.origin.x, result.origin.y, result.size.width, result.size.height); // x: 20.000000, y: 10.000000, width: 40.000000, height: 160.000000 |
Actually the above NSLog is how I have been inspecting CGRect for the past 2 years. Right after I published the first version of this blog post I was pointed out to me that there is an even more elegant method: NSStringFromCGRect. Wow, a third as much key strokes.
NSLog(@"%@", NSStringFromCGRect(result)); // {{20, 10}, {40, 160}} |
Wway more elegant, I’m sure you’ll agree? (Thanks Matt and Thomas But that’s the point of making these write ups. You learn a bit from writing them and you learn a bit more when other pros tell you the mistakes you made.
from: http://www.cocoanetics.com/2010/07/cgrect-tricks/
Subscribe to:
Posts (Atom)