Long ago, I have this dirty code to fix my sorting need on a specific case. However, the bottom line is one can’t (and shouldn’t) have a List that contains mixed numbers and non-numbers and be sorting it numerically Collections.sort(myList, new Comparator<MyObj>() { @Override public int compare(MyObj o1, MyObj o2) { [...]
baran
Long ago, I needed to count JSON object and i had done something silly by stringifying the object which is an overkill. Following is better: json = { "Ajazz":{"lo":"0","hi":"0.8"}, "Bjazz":{"lo":"0","hi":"0.8"}, "Cjazz":{"lo":"0","hi":"0.8"} } i = 0; for(var j in json) i++; alert(i);
baran
<a href="#tabs-0">My rolls</a> <a href="#tabs-1">Your balls</a> <a href="#tabs-2">His arms</a> what i needed was to find out active link (clicked link) and here you go: $(document).ready(function() { $("a", "#tabs").click(function() { var href = $(this).attr("href"); alert( "link in tabs clicked : " + [...]
baran
I was always surprised with this arcane behavior of Jquery: <div class="wrapper">... $("div.wrapper").click(function() { alert("1123"); }); and above fails so psychological acceptance is not correct in this occasion. Correct one is below: jQuery(document).on("click", ".wrapper", function() { alert("1123"); });
baran
To reach keys and values of a JSON object, all you need to do is: var jazz = { phone: "79 950 90 94", "foo-1": "2999", "foo-0": "1999", "foo-3": null, address: "Rue des Honnelles", city: "Acapulco", "baz-0": "0", "baz-1": "2000", "baz-2": "3000", "baz-3": "5000" } // checking alert( jazz["baz-0"] ); var jazzArray = []; for(var j in jazz) [...]
baran
This might be handy or maybe an overkill for checking undefined or null state with JS. In practice, i don’t really do such checks in frontend but i sometimes do check, especially for debugging purposes. // Test for conditions individually if (typeof myvar == 'undefined') { alert('myvar is not defined'); } else if (myvar == null) { [...]
baran
Long time ago, I needed to post some JSON data data to my servlet and here you go: <script src="http://code.jquery.com/jquery-latest.js"></script><script> $(document).ready(function() { $("#myformid").on('submit', function() { $.ajax({ dataType: "json", url: "/servlets/baran.JSONExample", data: [...]
baran
Long ago again, I implemented this JSON parser and btw, the following will fail if you are not using proper libraries, commons-collections-3.2.1 and commons-lang 2.6 import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import [...]
baran
There was a time when I needed to find out whether a button is clicked in previous.aspx and the result shall be traceable in current.aspx. Well here you go! private void LogLastButton(Button button) { Session["LastButtonId"] = button.ID; } protected void ButtonView_Click(object sender, EventArgs e) { this.LogLastButton((Button)sender); } [...]
baran
To add a metatag, Page_Load might be an option. Though, i would add the tag in the frontend in a normal scenario. if (Page.IsPostBack) { HtmlMeta metaTag = new HtmlMeta(); metaTag.HttpEquiv = "X-UA-Compatible"; metaTag.Content = "IE=edge,chrome=1"; Header.Controls.Add(metaTag); }
baran