Friday, May 6, 2011

css: how to format contact entry screen

I am trying to nicely format contact screen in my aspx page using CSS. With the following code, I am unable to click into the txtEmailAddress. If I take out padding:100px from the txtSubject Span element, then I am able to click into txtEmailaddress and edit. please help...

<div>
<span>
Your Email Address :    
</span>
<span style="padding:100px">
<asp:TextBox ID="txtEmailAddress" runat="server"></asp:TextBox>        
</span>

<br />
<span>
                    Subject :    
</span>
<span  style="padding:100px">
                <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox>        
</span>                
<br />
</div>
From stackoverflow
  • i tried copying and pasting and experienced the same behaviour, i.e. with padding on the subject span i couldn't click into txtEmailAddress. I am running IE8 on vista SP1 if that helps at all. I also noticed that the text boxes were not aligned.

    Whilst it doesn't answer your question, have you thought about using Label tag and styling these tags. The form will be more accessible this way. You can find out more about this approach on alistapart here:

  • Perhaps the following would suit your purposes better:

    <fieldset>
    <legend>Add a heading if you want one</legend>
    <div>
    <asp:Label id="lblEmail" runat="server" text="Your Email Address:" AssociatedControlID="txtEmailAddress">
    </asp:Label>
    <asp:TextBox ID="txtEmailAddress" runat="server"></asp:TextBox>        
    </div>
    <div>
    <asp:Label id="lblSubject" runat="server" text="Subject:" AssociatedControlID="txtSubject">
    </asp:Label>
    <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox>        
    </div>
    </fieldset>
    

    You can then add your layout using CSS to the fieldset, label and input elements specifically, e.g.

    fieldset label
    {
      margin-right: 2em;
      width: 20em;
    }
    
    fieldset input
    {
      display: inline;
    }
    

    Or some variation thereof.

Accessing Google Spreadsheets with C# using Google Data API

I'm having some information in Google Spreadsheets as a single sheet. Is there any way by which I can read this information from .NET by providing the google credentials and spreadsheet address. Is it possible using Google Data APIs. Ultimately I need to get the information from Google spreadsheet in a DataTable. How can I do it? If anyone has attempted it, pls share some information.

From stackoverflow
  • I'm pretty sure there'll be some C# SDKs / toolkits on Google Code for this. I found this one, but there may be others so it's worth having a browse around.

  • http://code.google.com/apis/gdata/articles/dotnet_client_lib.html

    This should get you started. I haven't played with it lately but I downloaded a very old version a while back and it seemed pretty solid. This one is updated to Visual Studio 2008 as well so check out the docs!

  • You can do what you're asking several ways:

    1. Using Google's spreadsheet C# library (as in Tacoman667's answer) to fetch a ListFeed which can return a list of rows (ListEntry in Google parlance) each of which has a list of name-value pairs. The Google spreadsheet API (http://code.google.com/apis/spreadsheets/code.html) documentation has more than enough information to get you started.

    2. Using the Google visualization API which lets you submit more sophisticated (almost like SQL) queries to fetch only the rows/columns you require.

    3. The spreadsheet contents are returned as Atom feeds so you can use XPath or SAX parsing to extract the contents of a list feed. There is an example of doing it this way (in Java and Javascript only though I'm afraid) at http://gqlx.twyst.co.za.

  • According to the .Net user guide: http://code.google.com/apis/spreadsheets/docs/2.0/developers_guide_dotnet.html

    Download the .Net client library: http://code.google.com/p/google-gdata/

    Add these using statements:

    using Google.GData.Client;
    using Google.GData.Extensions;
    using Google.GData.Spreadsheets;
    

    Authenticate:

    SpreadsheetsService myService = new SpreadsheetsService("exampleCo-exampleApp-1");
    myService.setUserCredentials("jo@gmail.com", "mypassword");
    

    Get a list of spreadsheets:

    SpreadsheetQuery query = new SpreadsheetQuery();
    SpreadsheetFeed feed = service.Query(query);
    
    Console.WriteLine("Your spreadsheets:");
    foreach (SpreadsheetEntry entry in feed.Entries)
    {
        Console.WriteLine(entry.Title.Text);
    }
    

    Given a SpreadsheetEntry you've already retrieved, you can get a list of all worksheets in this spreadsheet as follows:

    AtomLink link = entry.Links.FindService(GDataSpreadsheetsNameTable.WorksheetRel, null);
    
    WorksheetQuery query = new WorksheetQuery(link.HRef.ToString());
    WorksheetFeed feed = service.Query(query);
    
    foreach (WorksheetEntry worksheet in feed.Entries)
    {
        Console.WriteLine(worksheet.Title.Text);
    }
    

    And get a cell based feed:

    AtomLink cellFeedLink = worksheetentry.Links.FindService(GDataSpreadsheetsNameTable.CellRel, null);
    
    CellQuery query = new CellQuery(cellFeedLink.HRef.ToString());
    CellFeed feed = service.Query(query);
    
    Console.WriteLine("Cells in this worksheet:");
    foreach (CellEntry curCell in feed.Entries)
    {
        Console.WriteLine("Row {0}, column {1}: {2}", curCell.Cell.Row,
            curCell.Cell.Column, curCell.Cell.Value);
    }
    
  • I wrote a simple wrapper around Google's .Net client library, it exposes a simpler database-like interface, with strongly-typed record types. Here's some sample code:

    public class Entity {
        public int IntProp { get; set; }
        public string StringProp { get; set; }
    }
    
    var e1 = new Entity { IntProp = 2 };
    var e2 = new Entity { StringProp = "hello" };
    var client = new DatabaseClient("you@gmail.com", "password");
    const string dbName = "IntegrationTests";
    Console.WriteLine("Opening or creating database");
    db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName); // databases are spreadsheets
    const string tableName = "IntegrationTests";
    Console.WriteLine("Opening or creating table");
    table = db.GetTable<Entity>(tableName) ?? db.CreateTable<Entity>(tableName); // tables are worksheets
    table.DeleteAll();
    table.Add(e1);
    table.Add(e2);
    var r1 = table.Get(1);
    

    There's also a LINQ provider that translates to google's structured query operators:

    var q = from r in table.AsQueryable()
            where r.IntProp > -1000 && r.StringProp == "hello"
            orderby r.IntProp
            select r;
    

Why only basicHttpBinding with silverlight and wcf?

Exact duplicate: http://stackoverflow.com/questions/661479/why-does-silverlight-2-only-support-wcf-basichttp-binding

Why only basicHttpBinding with silverlight and wcf? Perhaps you have a link that covers this, you don't have to do a bunch of typing :+>

From stackoverflow
  • Hm, I am pretty sure this is duplicate, but can't find it. I think the short answer is that BasicHttpBinding is the only binding that works in Partial Trust.

    (EDIT: found the dup, linked in question now)

  • I found several links for this but no definitive answer. Smells like Silverlight was designed against ASMX web services for Web service style communication and the way to get WCF to play with older clients expecting an ASMX web service is to use the basicHttp binding.

    This link gives you a fully worked example (using Beta2 of Silverlight).
    http://msdn.microsoft.com/en-us/magazine/cc794260.aspx

    A standard WCF service can be invoked by a Silverlight app as long as the Silverlight app has a binding of type basicHttpBinding. You must either make sure you change the default binding of the WCF service from wsHttpBinding to basic­HttpBinding or create a new binding of type basicHttpBinding

    This Reference says the same thing but again offers no explanation. http://timheuer.com/blog/archive/2008/03/14/calling-web-services-with-silverlight-2.aspx

    Silverlight communicates using the BasicHttpBinding for WCF

  • A couple of answers: (1) Silverlight 4 now makes the Net.TCP binding available, which is darned handy when it's not blocked, since it's dramatically faster (see here for details). So clearly there's nothing inherent in the Silverlight architecture which prevents it from using other bindings.

    (2) As for why Silverlight doesn't make use of the other WS* Http-based bindings, it's just a guess, but I wouldn't be surprised if those bindings made use of the HTTP protocol in ways that Silverlight's limited HTTP stack won't support, probably for security reasons. For instance, I know that Silverlight limits the content headers that you can place on an HTTP request, and if any of the WS-* protocols require custom headers, or headers that might represent a security risk, MS would want to prevent that.

    (3) Of course, it's also possible that MS just hasn't gotten around to it yet. They've done a lot with Silverlight in the last couple years -- but presumably they have to prioritize their features.

JSON.Net: Convert JSON string from XML string to instance issue

I have the following function:

public static T GetInstance<T>(string xmlString)
{
   var xmlDoc = new XmlDocument();
   xmlDoc.Load(new StringReader(xmlString));
   string jsonString = JsonConvert.SerializeXmlNode(xmlDoc.DocumentElement);
   T instance = JsonConvert.DeserializeObject(jsonString, typeof(T)) as T;
   return instance;
}

It works fine for normal XML strings. However, if the input XML string contains comments such as :

....
<!-- some comments ... 
-->
....

Then the function call to JsonConvert.DeserializeObject() will throw an exception:

Newtonsoft.Json.JsonSerializationException was unhandled
Message="Unexpected token when deserializing object: Comment"
Source="Newtonsoft.Json"
StackTrace:
   at Newtonsoft.Json.JsonSerializer.PopulateObject(Object newObject, JsonReader reader, Type objectType)
   ....

Either I have to trim out all the comments in the XML string, or if I can use any option settings in JsonConvert to ignore comments.

For the first option, if I have to take all the comments out by using XmlDocument, is there any options in XmlDocument available to convert an XML string to nodes-only XML string?

For the second option, I prefer, if there is any option in Json.Net to ignore comments when desialize to object?

From stackoverflow
  • I think the best way for me right now is to remove all the comment nodes from the xml string first.

    public static string RemoveComments(
            string xmlString,
            int indention)
    {
       XmlDocument xDoc = new XmlDocument();
       xDoc.PreserveWhitespace = false;
       xDoc.LoadXml(xmlString);
       XmlNodeList list = xDoc.SelectNodes("//comment()");
    
       foreach (XmlNode node in list)
       {
          node.ParentNode.RemoveChild(node);
       }
    
       string xml;
       using (StringWriter sw = new StringWriter())
       {
          using (XmlTextWriter xtw = new XmlTextWriter(sw))
          {
            if (indention > 0)
            {
              xtw.IndentChar = ' ';
              xtw.Indentation = indention;
              xtw.Formatting = System.Xml.Formatting.Indented;
            }
    
            xDoc.WriteContentTo(xtw);
            xtw.Close();
            sw.Close();
          }
          xml = sw.ToString();
        }
    
      return xml;
      }
    

    And this is my function to get instance from xml string:

    public static T GetInstance<T>(string xmlString)
    {
      srring xml = RemoveComments(xmlString);
      var xmlDoc = new XmlDocument();
      xmlDoc.Load(new StringReader(xml));
      string jsonString = JsonConvert.SerializeXmlNode(xmlDoc.DocumentElement);
      T instance = JsonConvert.DeserializeObject(jsonString, typeof(T)) as T;
      return instance;
    }
    

Git ignore file for C projects

I've just started to learn C (using Thinking In C) and I'm wondering about what files I should be ignoring in a C project's git repository.

No suggestion can be too obvious -- I'm a total noob. Thanks!

From stackoverflow
  • I guess there will be a few generated files that you don't wan't to be sticking in your repo (assuming your build output dir is in your git heirachy):

    • object files (.o, o.obj)
    • libraries (.lib)
    • DLLs, shared objects (.so, .dll)
    • Executables (.exe, a.out ?)

    GIT ignore files are something I tend to do iteratively. "Hey, I don't need those things in my repo" ...

    Edit: re dmckee's comment

    Yep, you definately want to be ignoring swap files, temp files etc. I have the following as a baseline for my .gitignore:

    • *.swp
    • .~
    • thumbs.db
    dmckee : If you editor makes automatic backups (ala emacs' *~ files), you can probably do without those too.
    Jakub Narębski : Usually you put ignoring of generated files in version controlled and transferred `.gitignore` file (so everybody will have generated files ignored), but ignoring backup files and other types of files depending on your environment (backup files can be *~ or *.bak) in not transferred repository .git/info/exclude (or in core.excludesfile set in ~/.gitconfig).
  • You can also setup your build to happen in a subdirectory say build and then you can ignore the whole thing inside .gitignore

    build/

    And you're done.

Overlaying a UIImage with a color?

I'm attempting to add a black overlay over some current UIImage's (which are white). I've been trying to use:

[[UIColor blackColor] set]; [image drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeOverlay alpha:1.0];

But it's not working, and I'm pretty sure set isn't supposed to be there.

From stackoverflow
  • -set is used to set the colour of subsequent drawing operations which doesn't include blits. I suggest as a first call, displaying another (empty) UIView over yout UIImageView and stting it's background colour:

    myView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    

    Obviously you should use the white and alpha values you want.

    Oliver : The problem with this is my UIImage isn't a rectangle block, it's an icon. Wouldn't this method also draw the color around the image? Basically, I just want to convert a white UIImage to a black UIImage.
  • You will want to clip the context to an image mask and then fill with a solid color:

    - (void)drawRect:(CGRect)rect
    {
        CGRect bounds = [self bounds];
        [[UIColor blackColor] set];
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextClipToMask(context, bounds, [myImage CGImage]);
        CGContextFillRect(context, bounds);
    }
    

    Note: myImage should be an instance variable that contains an UIImage. I'm not sure whether it takes the mask from the alpha channel or the intensity so try both.

  • In addition to the solution by rpetrich (which is great by the way - help me superbly), you can also replace the CGContextClipToMask line with:

        CGContextSetBlendMode(context, kCGBlendModeSourceIn); //this is the main bit!
    

    It's the SourceIn blendmode that does the job of masking the color by whatever is in the GetCurrentContext.

  • I just wrote a tutorial that will help with this. My approach gives you a copy of a UIImage, with the color alterations that you want. rpetrich's approach is great, but requires that you're creating a subclass. My approach is just a few lines of code that can be dropped in wherever you need them. http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage

Generating Professional Graphs In Windows

In Windows, I am looking at generating professional graphs using any mainstream programming language (C#, VB.Net, Java, PERL, etc). The best free looking graphs I have found so far is Microsoft Chart Controls for .NET. What other graph controls/modules do you suggest?

Note: Added free to the requirements.

From stackoverflow
  • jFreeChart is [one of] the best solution[s] out there for Java. I totally recommend it.

  • Have you seen Zedgraph?. It is LGPL, but rather extensive.

  • There are dozens and dozens of commercial charting components out there. Personally, I like the DevExpress tools.

    XtraCharts is really good, well documented and relatively affordable.

  • GLE is a scripting language designed for generating professional quality graphs and diagrams for publication. It uses LaTeX for typesetting, so including equations in your graphs is a snap and they look great. Christopher Bishop used GLE for all the diagrams in his textbook, "Pattern Recognition and Machine Learning," and let me tell you, they looked great. Open-source to boot!

    First you write the GLE script and tell it to accept a text file as the graph input data. Then, you can generate the data set in whatever language you want, export as a text file, and call the GLE script to generate the graph.

    More info from the website:

    GLE (Graphics Layout Engine) is a graphics scripting language designed for creating publication quality graphs, plots, diagrams, figures and slides. GLE supports various graph types (function plots, histograms, bar graphs, scatter plots, contour lines, color maps, surface plots, ...) ... GLE's output formats include EPS, PS, PDF, JPEG, and PNG.