Jump to content

Lassie

Members
  • Posts

    390
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Lassie's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. Thanks for confirming that. Being a pensioner, your first option is the way i will go.
  2. I want to convert a program from what I think is Ruby to PHP as I have no knowledge of Ruby. Could someone confirm if the posted code is Ruby please and if there are any known methods to help with a conversion. Is it possible to run Ruby code within PHP? The background to this request is that I have a 3 axis accelerometer and would like to construct a pedometer. I have the data logged to a file but coding the pedometer is a challenge. I found the following ,A Pedometer in the Real World Dessy Daskalov' which does what I want but I dont follow the code. For those interested a link to the article:-http://www.aosabook.org/en/500L/a-pedometer-in-the-real-world.html Any guidance appreciated and I hope this is the right forum. class Parser attr_reader :parsed_data def self.run(data) parser = Parser.new(data) parser.parse parser end def initialize(data) @data = data end def parse @parsed_data = @data.to_s.split(';').map { |x| x.split('|') } .map { |x| x.map { |x| x.split(',').map(&:to_f) } } unless @parsed_data.map { |x| x.map(&:length).uniq }.uniq == [[3]] raise 'Bad Input. Ensure data is properly formatted.' end if @parsed_data.first.count == 1 filtered_accl = @parsed_data.map(&:flatten).transpose.map do |total_accl| grav = Filter.low_0_hz(total_accl) user = total_accl.zip(grav).map { |a, b| a - b } [user, grav] end @parsed_data = @parsed_data.length.times.map do |i| user = filtered_accl.map(&:first).map { |elem| elem[i] } grav = filtered_accl.map(&:last).map { |elem| elem[i] } [user, grav] end end end end
  3. Thank you very much. Will do.
  4. I want to modify a script that send SMS and I am using a switch statement to send different messages dependent on a condition. The original script works fine but no message is sent with my modified script. I wonder if some part is out of scope? Switch SMS.php
  5. Hi, Thanks for that. I would like to implement the the logic in PHP and I agree that I should try it myself. Thanks
  6. Hi, I am new to JS but OK in PHP. I would like to use JS code similar to this' http://www.geocachingtoolbox.com/index.php?page=dancingMen' a php program. My problem is understanding how this works. I have posted what seem to be the two key functions and my first attempt to simplify things as well as the link the above link in the hope somebody can get my thinking working in the right direction particularly in understanding the two functions. Many thanks for a starter for ten, <script type="text/javascript"> var validChars= new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') var validNums= new Array('0','1','2','3','4','5','6','7','8','9'); function textToIm(){ chars=document.getElementById('dancingMenText').value; splitChars=chars.split(''); newDiv=''; for(i=0; i<splitChars.length; i++){ lowerChar=splitChars[i].toLowerCase(); if (validChars.indexOf(lowerChar)>-1){ if (i+1==splitChars.length || splitChars[i+1]==' ' || splitChars[i+1]=='\n'){ newDiv+='<img src="pages/dancingMen/'+lowerChar+'v.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; }else{ newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; } }else if (validNums.indexOf(lowerChar)>-1){ newDiv+='<img src="pages/dancingMen/'+lowerChar+'.gif" alt="'+splitChars[i]+'" title="'+splitChars[i]+'">'; }else if (lowerChar!=' '){ newDiv+=splitChars[i]; } } newDiv = newDiv.replace(/\n\r?/g, '<br>'); if (chars.length==0){ newDiv=''; } document.getElementById('dancingMenDiv').innerHTML=newDiv; } function imToText(char,space){ if (space==1){ document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'v.gif" alt="'+char+'" title="'+char+'">'; document.getElementById('dancingMenText').value+=char+' '; }else{ document.getElementById('dancingMenDiv').innerHTML+='<img src="pages/dancingMen/'+char+'.gif" alt="'+char+'" title="'+char+'">'; document.getElementById('dancingMenText').value+=char; } } </script> index.php
  7. I am trying to build a simple program to illustrate drawdown in a pension scenario. I have a syntax error that I cant find however. Any help appreciated. <?php if(!$_POST){ ?> <table border=1> <form action="" method="post"> <tr> <td> Initial Capital: <td> <input type="text" name="amount"> <td><br> <td> Growth Rate pa: (in %) <td> <input type="text" name="rate"> <td> Period in Yrs: <td> <input type="text" name="years" maxlength="4"> <td> Yearly Drawdown: <td> <input type="text" name="drawdown" maxlength="5"> <td> <input type="submit"> </form> </table> <?php }else{ if($_POST){ $amount = $_POST['amount']; $rate = $_POST['rate']; $time = $_POST['time']; $number = $_POST['years']; $drawdown = $_POST['drawdown']; $amount2 = (float)$amount; $rate2 = (float)$rate; $drawdown2 =(float)$drawdown; $year = 1 ?> <table border=1> <tr><td> Initial Capital: <?php echo "$start" ?></td> <td>Interest: <?php echo "$rate" ?>%</td> </table> <table border=1> <tr> <th>Years</th> <th>Amount</th> <th>Remaining Capital</th> </tr> <?php while ($year <= $number) { //calculate interest and deduct drawdown $Solve_Interest = ($amount2 * $rate2 * $time) / 100; $Total_Amount = ($amount2 + $Solve_Interest); $Remaining_Capital = ($Total_Amount - $drawdown2); echo "<tr><td>"; echo $year; echo "</td><td>"; echo "<tr><td>"; echo $Solved_Interest; echo "</td><td>"; echo "<tr><td>"; echo $Remaining_Capital; echo "</td><td>"; echo "</tr>"; $year = $year + 1; $amount2 = $Remaining_Capital; } } ?>
  8. change password

  9. Right. Many thanks I have a result, now to sort out the other isssues.
  10. I am trying to make a google map with multiple markers. I have data drawn from mysql and passed to the js. I cant however get the variables for lat and lng to be recognised in my script. Any help appreciated. <script> var coords = <?php echo $output?>; console.dir(coords); </script> <div id="map" style="width: 500px; height: 400px;"></div> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> //replace with coords, postcode, lat, lng // verify we have the right info for (var i = 0; i < coords.length; i++) { document.write('Postcode: '); document.write(coords[i].postcode); document.write('<br />'); document.write('Latitude: '); document.write(coords[i].latitude); document.write('<br />'); document.write('Longitude: '); document.write(coords[i].longitude); document.write('<br />'); } var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(0, -0), mapTypeId: google.maps.MapTypeId.ROADMAP }); var infowindow = new google.maps.InfoWindow(); var marker, i; for (i = 0; i < coords.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(coords[i].latitude[1], coords[i].longitude[2]), map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(coords[i].postcode[0]); infowindow.open(map, marker); } })(marker, i)); } </script>
  11. Ok I understand. I will get this working and then apply that logic. Thanks very much.
  12. Thanks. So will $output = json_encode($coords); <script> var coords = <?php echo $output?>; </script> <div id="map" style="width: 500px; height: 400px;"></div> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> //replace with coords, postcode, lat, lng var locations = [coords]; or (var i = 0; i < locations.length; i++) { document.write('Postcode: '); document.write(locations[i].postcode); document.write('<br />'); } work. thanks
  13. Ok, my problem is how to use the properties and values.
  14. I opened the developer console in chrome and it shows an array but not the values. Array[9]0: Object1: Object2: Object3: Object4: Object5: Object6: Object7: Object8: Objectlength: 9__proto__: Array[0] I have very little js expeireince so I am stuck. I want the values in an arry si can iterate through. Any suggested approaches I can try, thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.