[Solved] How should I calculate the average speed by road segment for multiple segments?

When averaging speeds, the harmonic mean is in need. The straight forward AVG() approach is wrong, the arithmetic mean yields the wrong result for average velocity. There is no predefined function for the harmonic mean, but it could be achieved with this query: SELECT segment, COUNT(*)/SUM(1e0/speed) AS avg_speed FROM T GROUP BY segment SQL Fiddle … Read more

[Solved] List with numbers and text

There are many options, I describe some of them for you use Dictionary<int, string>Pros: very fast lookupCons: you can not have two string with same number, you don’t have a List var list2d = new Dictionary<int, string>(); list2d[1] = “hello”; list2d[2] = “world!”; foreach (var item in list2d) { Console.WriteLine(string.Format(“{0}: {1}”, item.Key, item.Value); } use … Read more

[Solved] Java Variable Substitution

This is normally solved with just a String#replaceAll, but since you have a custom, dynamic replacement string, you can to use a Matcher to efficiently and concisely do the string replacement. public static String parse(String command, String… args) { StringBuffer sb = new StringBuffer(); Matcher m = Pattern.compile(“\\$(\\d+)”).matcher(command); while (m.find()) { int num = Integer.parseInt(m.group(1)); … Read more

[Solved] Split calculator expression with binary and unary operations [closed]

I found easy solution. You could just write it instead of complain that there is no code in the question. string expression;//my calculator expression string[] operators;//array that contains both unary and binary operators. for(int i=0;i<operators.length;i++) { expression = expression.replace(operators[i],” “+operators[i]+ ” “); } string[] Values= expression.split(” “); solved Split calculator expression with binary and unary … Read more

[Solved] i have stored array in database as a string how can retrieve that array?

use JSON_ENCODE first before saving the array to DB ,then use JSON_DECODE if you want to get again the contents $arr = array( “item_number1” => “1”, “payment_date” => “04:21:34 Dec 06, 2014 PST”, “payment_status” => “Completed”, “first_name” => “sdfsd”, “last_name” => “parsdfsdandekar”, “quantity1” => “1” ); echo json_encode($arr); Result after JSON_ENCODE (Array to JSON String): … Read more

[Solved] HTML please Hilp

I tried to understand your question but it is hard to visualize exactly what you want. So I’ll just clean and update your code (i.e. bring it into the 21st Century). Please don’t use the <font> tag or the align attribute anymore. It’s 2016. If this is a heading, use <h1>, not <p>. Tags work … Read more

[Solved] Pass value from View Holder

Then create a hashmap and whenever updation takes place save the data in hashmap. Inherit getItem(int index) method in adapter with HashMap as return type & and return the data in that method for corresponding index. HashMap<String, Object> hashMap = new HashMap<String, Object>(); @Override public HashMap getItem(int i) { return hashMap.get(i); } Like if user … Read more

[Solved] Quicker way to animate each word of a sentence?

Though, the question is not very clear, but here is my attempt to give you initials, as per my understanding. var sentence = $(‘div#content’).text(); var words = sentence.split(‘ ‘); var spanWords = []; $(words).each(function(i,word){ if($.trim(word).length) { var span = $(‘<span>’); span.text(word); spanWords.push(span) spanWords.push(‘&nbsp;’) } }); $(‘div#content’).html(spanWords) var start = function(element){ if(element.next().length){ setTimeout(function(){ element.css({color: “#000”}); start(element.next()) … Read more

[Solved] Change Activities’ Fragment Inside the Fragment

Use below method public static void openFragment(FragmentManager manager, Fragment targetFragment) { try { String fragmentName = targetFragment.getClass().getName(); manager.popBackStack(); manager.beginTransaction() .replace(R.id.frameLayout, targetFragment, fragmentName) .addToBackStack(fragmentName) .commit(); } catch (Exception e) { e.printStackTrace(); } } call this method each time when you are opening your fragment. You have to pass two params to this method. targetFragment is the … Read more

[Solved] Form Password Validation without using regex [duplicate]

As you now accepted to use RegEx, I adapted the solution based on this post https://stackoverflow.com/a/16707675/4339170: function validate() { var p = document.getElementById(‘pass’).value var errors = [] //if (p.length < 8) { // errors.push(“Your password must be at least 8 characters”) //} if (p.search(/[a-z]/) < 0) { errors.push(“Your password must contain at least one lowercase … Read more