Posts Tagged ‘elements’

How can we limit the capacity of an NSMutableDictionary?

Monday, August 23rd, 2010

Is there any way to create a mutable dictionary with a capacity limit rather than an initial capacity?

Say you want to create a dictionary that will only ever have, at most, 100 entries.

The capacity argument for the dictionary is an initial capacity that will be simply increased if you add more elements than you want so it’s not suitable.

how to add/insert conditional node into XML using linq to XML

Monday, August 23rd, 2010

I generated an xml file like this:

 XElement employees =
                new XElement("Work",
                   new XElement("record",
                      new XElement("Name", textBox1.Text),
                      new XElement("Phone", "206-555-0144"),
                      new XElement("Address",
                            new XElement("Street1", "123 Main St"),
                            new XElement("City", "Mercer Island"),
                            new XElement("State", "WA"),
                            new XElement("Postal", "68042")
                                    )),
                     new XElement("record",
                      new XElement("Name", "22222"),
                      new XElement("Phone", "353245345"),
                      new XElement("Address",
                            new XElement("Street1", "sdfain St"),
                            new XElement("City", "asdf Island"),
                            new XElement("State", "QLD"),
                            new XElement("Postal", "54322")
                                    )),
                      new XElement("record",
                      new XElement("Name", "Peter"),
                      new XElement("Phone", "1234"),
                      new XElement("Address",
                            new XElement("Street1", "sd St"),
                            new XElement("City", "cbr"),
                            new XElement("State", "act"),
                            new XElement("Postal", "2600")
                                    )
                                )
                             );

Later I wish to add new child node under parent node “record” based on a condition (where name=”peter”), something like this:

empFile.Elements().Where(r => (string)r.Element("Name") == "Peter").add(new XElement("record", new XElement("Mobile", "3253425"), new XElement("Work", 999999)));

How can i achieve this?

Show tab bar after its hidden

Monday, August 23rd, 2010

Hi folks,

Is there any way to show a tab bar after it has been hidden?
Got a tabbar-nav structure. For one of the tabs, I need to hide the tab bar for its 2nd and 3rd level view. But at the same time I will need to show its 1st and 4th view.

The sample code from Elements isn’t really applicable here I think.

Any help is greatly appreciated.

IE 8 Quirks vs Standards retrieving offsetHeight/offsetWidth

Monday, August 23rd, 2010

I am in the process of converting my application to use XHTML strict mode (it didn’t have a DOCTYPE before). However, I noticed a significant degradation when getting offsetHeight/offsetWidth. This is very noticeable on pages with large number of DOM elements, let’s say a table with 1 column by 800 rows, the cells only have a piece of text. Visiting each descendant element in that table to obtain their offset dimension is way slower than when IE renders the page in Quirks mode.
Why is that the case? and does anybody know tips to help IE calculate those offsetValues?

C# program that dumps the entire tree of your LocalMachine to the console?

Monday, August 23rd, 2010

im trying to write a simeple console app that dumps the contents of the local machine to the consol. the output shouuld look something like :

HKEY_LOCAL_MACHINE
HKEY_LOCAL_MACHINEBCD00000000
  HKEY_LOCAL_MACHINEBCD00000000Description
    KeyName: BCD00000000
    System: 1
    TreatAsSystem: 1
    GuidCache: System.Byte[]
  HKEY_LOCAL_MACHINEBCD00000000Objects
    HKEY_LOCAL_MACHINEBCD00000000Objects{0ce4991b-e6b3-4b16-b23c-5e0d9250e5d9}
      HKEY_LOCAL_MACHINEBCD00000000Objects{0ce4991b-e6b3-4b16-b23c-5e0d9250e5d9}Description
        Type: 537919488
      HKEY_LOCAL_MACHINEBCD00000000Objects{0ce4991b-e6b3-4b16-b23c-5e0d9250e5d9}Elements
        HKEY_LOCAL_MACHINEBCD00000000Objects{0ce4991b-e6b3-4b16-b23c-5e0d9250e5d9}Elements16000020
          Element: System.Byte[]

i havent had much luck on researching how to do this. any help would be greatly appreciated. thnx

[CSS21] Issue 142: the term “ancestor box”

Sunday, August 22nd, 2010
This is proposed text for issue 142[1]. Section 10.1 uses the term
"ancestor box," by which it means the "box of an ancestor element." But
apparently the term causes confusion. That is probably because in some
cases and in some implementations the boxes form a tree. (CSS doesn't
say that the boxes form a tree, only that each box is associated with an
element and the elements form a tree.)

So here is a rewrite to avoid the term. The following all occur in
section 10.1:

  - Replace the first occurrence of "ancestor box" by "ancestor
    element".

  - Replace the occurrence of "ancestor boxes" (in the example) by
    "ancestor elements".

  - Replace the phrase "the nearest positioned ancestor box" (at the
    end of the example) by "the padding edge of the nearest positioned
    ancestor".

[1] http://wiki.csswg.org/spec/css2.1#issue-142

Bert

Jquery: Turn 3 arrays in to different objects with different IDs

Sunday, August 22nd, 2010

I’ve been fooling around with a very minimalistic jquery admin area menu. The thing is I want jQuery to build 3 equal menus with different ID’s. I managed to do this by creating a function and call it 3 times with different variables, but I’d like to ask my first question on this lovely community:

What is the most minimalistic and efficient way of creating 3 elements with different IDs and content?

d=['Varer','Kate','Produ','Tilbud','Sider','Info','Pref'];

e=['Varer1','Kate1','Produ1','Tilbud1','Sider1','Info1','Pref1'];

f=['Varer2','Kate2','Produ2','Tilbud2','Sider2','Info2','Pref2'];

function menu(){
var e='';
$.each(d,function(a,b){e+='<a href=#'+b+'>'+b+'</a>'});
$('body').append('<div id=c>'+e+'</div>');}
menu();

Thanks in advance

STL set of map iterators

Sunday, August 22nd, 2010

I have an stl unordered_map and I would like to store references to elements in that map. I would like there to be no duplicate references. I thought I could create an set of iterators which pointed to elements. For one I wasn’t sure that it would recognise , but even so I got some long template errors which I think boiled down to there being no comparison operator < for iterators.

I then tried an unordered set compiling with g++ -std=c++0x but got pages of errors.

How can I achieve this goal?

#include <set>
#include <unordered_map>
#include <unordered_set>

int main() {

  typedef std::unordered_map<int, float> umap;
  umap my_map;

  umap::const_iterator itr;
  for (int i=0;i<10000000;i++) {
    my_map[i] = float(i);
  }

 umap::iterator my_it1 = my_map.find(43);
 umap::iterator my_it2 = my_map.find(44);
 umap::iterator my_it3 = my_map.find(44);

 std::unordered_set<umap::iterator> my_its;
 my_its.insert(my_it1);
 my_its.insert(my_it2);
 my_its.insert(my_it3);

 return 0;
}

[jQuery, Form, Select] Selecting an option by its text

Sunday, August 22nd, 2010

Hi, I’m developing a web page using django and I want to add some javascript to a form using jQuery. Basically I want to select an option in a form depending on an another selection.
I need to use option’s text and not option’s values because option’s values are generated dynamically by django.

An extract of my code:

javascript

     $("#id_propietario").change(
        function() {
            if ($("#id_propietario").text() == '{{ usuario.username }}') {
                alert('test');
            } else {
                $("#id_adeudado").val($("#id_adeudado option[text='{{ usuario.username }}']").val());
            }
        }
      );

html form elements

 <p><label for="id_propietario">Propietario:</label> <select name="propietario" id="id_propietario">
 <option value="" selected="selected">---------</option>
 <option value="1">elio</option>
 <option value="2">up1</option>
 <option value="3">up2</option>
 </select></p>
 <p><label for="id_adeudado">Adeudado:</label> <select name="adeudado" id="id_adeudado">
 <option value="" selected="selected">---------</option>
 <option value="1">elio</option>
 <option value="2">up1</option>
 <option value="3">up2</option>
 </select></p>

I’m using jQuery 1.4, this behavior apparently has changed from 1.3 to 1.4 where you could directly use

$("#id_adeudado").val('{{ usuario.username }}');

Note that django is replacing {{ usuario.username }} with the current username. My code isn’t working because jQuery isn’t selecting the option element using the text=’value’ selector.
How can I overcome this problem?

Thanks in advance

p.s: it’s my first time using jQuery

Add “details view” to UITableView

Sunday, August 22nd, 2010

I have a UITabbar with multiple view controllers. One of them is a UITableView. The tableview is stored in a nib where the file owner is a UITableViewController.

I’d like the tableview to show a “detail view” (custom view with a UILabel and some other elements) once a table cell is selected. My approach was to add the new details view as a child view to the UITableView:

[self.view addSubView:[detailsViewController view]]

Unfortunately that doesn’t create the effect I want. As a subview of the UITableView, I can scroll beyond the added details view and see the underlying table entries. UINavigationBar is an option, but since there’s no deeper hierarchy, I’d prefer a simple custom view with a close button. Any suggestions?