gmaps4rails v2 methods / functions / variables - ruby-on-rails

I was hoping for some clarification on when and where you can call certain methods.
clusterer (Do you access this through the handler? Do you clear the clusterer as a whole, or do you clear individual markers from the clusterer?)
addListener (I see this sitting in base_builder.coffee, but have no idea how to interact with it)
#hash = Gmaps4rails.build_markers(#events) do |event, marker| (Do all of the builders work here?)
primitives (when, maybe why, would I need to use these? I see it in the common.coffee, which is why I ask. I don't want to be missing anything.)
I'm sure I'll have more, as I keep using it... but these should get me moving nicely.
update
new question...

clusterer (Do you access this through the handler? Do you clear the clusterer as a whole, or do you clear individual markers from the clusterer?)
In 2.0.4 you can do handler.removeMarkers(array) and handler.removeMarker(marker)
addListener (I see this sitting in base_builder.coffee, but have no idea how to interact with it)
only useful if you create your own builder, you can access the same method thanks to the primitives, or write it with plain google maps commands: do you really need to abstract on your level?
#hash = Gmaps4rails.build_markers(#events) do |event, marker| (Do all of the builders work here?)
It's just a convenient way to create json. If you need custom json, build it with your own json builder.
primitives (when, maybe why, would I need to use these? I see it in the common.coffee, which is why I ask. I don't want to be missing anything.)
This is an abstraction in the gem: as an injected dependency it lets me test easily. You can use it, but its not required.

Related

How to implement Object.try! in Ruby on Rails?

I'd like to shorten code like the following:
content = content.join("\n") if content.respond_to? :join
into this:
content.try!(:join, "\n")
Is this a good idea, and can it be implemented in terms of the existing Object.try?
If I understand correctly, you want a version of try that modifies the object in-place, as in the difference between x = x.reverse and x.reverse!
To answer your questions...
Is this a good idea
No, it's not, it's actually impossible.
Can it be implemented in terms o the existing Object.try?
No, it can't, either with or without Object.try, it cannot be implemented at all. You cannot change an object's type in-place.
Using .join on an array produces a string. You cannot change an array in-place to become a string. This is why there is no join! method in the first place. Many of the methods on Array and Enumerable have versions with and without !. Many other methods do not have a ! version. This is because the ! version cannot be implemented.
In general, if you have a method like reverse and it's in-place equivalent reverse! you can already use try just fine:
content.try(:reverse!)
If the ! method doesn't already exist, such as join and the non-existent join!, it's because it cannot work, and you cannot make it work with a hypothetical try!.
Note that you can make something like this work with a proxy object, but this is a horrible overwrought solution to a nonexistent problem.
Just use content = content.join("\n") if content and be done with it.

Where is 's' object cached when using AppMeasurement in DTM

Omniture's basic page tracking function, s.t(), was not crafted for AJAX implementation. Unlike the onclick s.tl() function which has some gating instructions with s.linkTrackVars and s.linkTrackEvents, the s.t() function just perpetuates every cached property through to the next call and beyond.
I used to be able to use a ClearVars function to empty out all of the s object's attributes, but now that I am using AppMeasurement and letting DTM manage my implementation with the most updated version of that library—which I want to keep doing—I can't call the s object. I get the same "ReferenceError: s is not defined" that another person asked about here!.
I tried following Crayon Violent's instructions within that post, but I can't seem to find where DTM is stashing the cached values in between Adobe calls. This code:
window.s = new AppMeasurement();
lets me change/clear the attributes of s, but it's not the s I'm looking for. When I call the next AJAX s.t() function, all of the cached values are still there.
In my experience working with DTM and AA, there has been no end to bugs and caveats and workarounds with DTM's "native integration" of AA. This is why I have more or less decided that the best thing I can do is to either manage the lib myself or else treat AA as a 3rd party script (100% implement it through rules, just ignore that it's available as a tool).
As mentioned in my answer you linked, that line of code only works to expose the AA object in the window namespace if you are managing the library yourself. When you configure DTM to manage the library, it will instantiate AA object itself, and it will be buried within its own code (Honestly, I don't know why DTM did this, considering AA puts a number of other variables in the global namespace that DTM does nothing about).
AFAIK there is no documented way to reference it, but one thing I have found that seems to work for me - which as a disclaimer to cover my own arse I do NOT officially endorse: use at your own risk - is to use the following to get a reference of it:
var s = _satellite.getToolsByType('sc')[0].getS();
This uses getToolsByType method to get an array of the SiteCatalyst (Adobe Analytics) objects setup as tools in DTM. It does this by looping through _satellite.tools and comparing _satellite.tools[n].settings.engine to what you passed to getToolsByType.
Then I use [0] to get the first one in the array, under the assumption that there's only one configured (most people only do one). Then the getS() object pulls together the s object based on the settings in DTM. So from there, you can do things with it, including making use of s.clearVars()

How to obtain all OIDs from all MIBs

I would like obtain a list of all OIDs in the MIBs that are loaded on a manager and display it to users so that they can choose which MIB object to perform the GET/SET request. I would also like to obtain the syntax and max-access of the object. I'm programming using C++. I want to parse the MIBs to obtain the OIDs, not use snmpwalk. I am trying to use the Net-SNMP MIB_API. I've looked at the manual page but am not clear of how to use the functions to achieve what I want to do.
I see that read_all_mibs() is already called when we call init_mib(). That means I don't need to call read_all_mibs() again, right? Could anyone please guide on what is the next step after init_mib() that I should do.
Any help would be much appreciated. Thanks.
You should look at the apps/snmptranslate.c file for an example of how to walk the loaded mib tree to get information like the syntax and max-access details.
And, no, if you call init_snmp() or init_mib() you don't need to call read_all_mibs()

asp:listbox how to provide data?

I'm having some trouble with in my MVC-View. The data for the listbox is passed by the controller and accessible via Model.templateList. So now I have to pass these data to the asp:listbox. Is there any way to do this or do I have to use some sort of DataProvider. What would be bad in terms of SoC. I considered using the Html-Helper Html.ListBox but I have no idea how to get actions like double-click and so on to work with it. Hope there are many smart people with some knowledge about this.
Thank you for reading
To bind to the list box you would using something like this
#Html.ListBox("ListBoxName", new SelectList(Model,"dataValueField", "dataTextField"));
with regards to the the actions you would need to use JavaScript. A google query like "listbox double click javascript" will help you get to the next level.

How do I call use_javascript after include_javascripts has been called?

In my layout, I'm calling include_javascripts() in my <head></head> section. Later on in my layout, I'm calling a component which makes use of use_javascript(), but, unfortunately, the javascript has been output, so this request falls on deaf ears.
I can think of a few approaches:
Put the call to `include_javascripts()` at the bottom.
At the moment I can't do this, because I'm using a CMS on top of symfony which uses a lot of inline javascript.
Override the include_javascript helper, or create a new one, which adds doesn't add anything, but adds it adds to a queue that a filter will take care of after rendering the page.
This is sort of like the common filter which was removed from 1.2. Obviously, they don't seem to like this approach.
Are there any other alternatives?
The use_javascript function simply adds the specified script to a collection, which is output by the include_javascripts function.
In order to have inline javascript in your code, you will need to use tags, since the use_javascript is pointless unless include_javascripts is called afterwards.
If you do not want to deal with filenames and such, you could always use sfConfig::get('sf_root_dir') . js/filename.js to grab your file.

Resources