mercredi 29 juin 2016

Bootstrap JavaScript Carousel Doesn't Stop Cycling

Twitter Bootstrap Version: 2.0.3

Example HTML code:

<!DOCTYPE html>
<html dir="ltr" lang="en-US" xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<link rel="stylesheet" type="text/css" media="all" href="reddlec/style.css" />
<script type="text/javascript">
$(document).ready(function() {
    $('.carousel').each(function(){
        $(this).carousel({
            pause: true,
            interval: false
        });
    });
});​
</script>
<script src="http://twitter.github.com/bootstrap/assets/js/jquery.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-transition.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-carousel.js"></script>
</head>
<body>
<div id="myCarousel" class="carousel slide">
  <!-- Carousel items -->
  <div class="carousel-inner">
    <div class="active item">…</div>
    <div class="item">…</div>
    <div class="item">…</div>
  </div>
  <!-- Carousel nav -->
  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>
</body>
</html>

CSS: Provided with bootstrap.css

Problem: As you can see, I've enabled paused mode, and disabled cycling. But when I click the carousel's left or right controls, the carousel starts cycling at the default interval (5 seconds per cycle) on mouseleave.

How do I forcefully disable cycling? I want the images to be cycled manually by the user.

You can test the problem live on my test site here.

CakePHP 3 Password Reset fix

I have the following code to reset my password via a link through email (that works fine).

In my User Controller:

 public function resetpw($token = null) {
        $resetpw = $this->Users->findByToken('id');
        if ($this->request->is('post')) {
            $pw = $this->request->data['password'];
            $pwtable = TableRegistry::get('Users');
            $newpw = $pwtable->find($resetpw);
            $newpw->password = $pw;
            if ($pwtable->save($newpw)) {
                 $this->Flash->success(__('Your password has been successfully updated.'));
                return $this->redirect(['action' => 'login']);
        }
            else {
                $this->Flash->error(__('Your password could not be saved. Please, try again.'));
             }
        }
    }

The Reset Password CTP file:

Resetting your password?

<?= $this->Flash->render(); ?>
<?= $this->Form->create() ?>
    <fieldset>
        <legend><?= __('Please enter your new password.') ?></legend>
        <?= $this->Form->input('password', ['label' => 'New Password']) ?>
        <?= $this->Form->input('confirmpassword', ['type' => 'password', 'label' => 'Confirm New Password']) ?>
    </fieldset>
    <?= $this->Form->button(__('Update password')); ?>
<?= $this->Form->end() ?>

I also have the following rules regarding comparing the two passwords:

public function validatePasswords($validator)
{
    $validator->add('confirmpassword', 'no-misspelling', [
        'rule' => ['compareWith', 'password'],
        'message' => 'The passwords are not the same.',
    ]);
    return $validator;
}

After typing in two identical passwords for both the password & comfirmpassword fields, I get the following error:

Unknown finder method "SELECT Users.id AS Users__id, Users.username AS Users__username, Users.password AS Users__password, Users.email AS Users__email, Users.role AS Users__role, Users.token AS Users__token FROM users Users WHERE Users.token = :c0"

I'm not really sure what this means and how I go about resolving it.

Angular (ionic) render true values from checkbox

I am using ionic + parse js sdk and would like to render only the true values from a checkbox.

Below is the scope:

$scope.Diagnosed = [
    { text: "Allergies", checked: true},
    { text: "ADHD", checked: false},
    { text: "Alcohol/Drug Dependence", checked: false},
    { text: "Asthma", checked: false},
    { text: "Autism", checked: false},
    { text: "Cancer", checked: false},
    { text: "Diabetes", checked: false},
    { text: "Eating Disorder", checked: false},
    { text: "Fertility Problems", checked: false},
    { text: "Heart Disease", checked: false},
    { text: "High Cholesterol", checked: false},
    { text: "Menopause", checked: false},
    { text: "Mood Disorders (e.g., anxiety, depression)", checked: false},
    { text: "Obesity", checked: false},
    { text: "Stroke", checked: false},
    { text: "Prefer not to answer", checked: false}

    ];

And I am rendering the values on a different page using the below code:

query.get(id,{
success: function(response){

  var currentStart = 1
  for (var i = currentStart; i < response.length; i++) {
    var object = response[i];
          }

 $scope.Details = {
     diagnosed: response.get('diagnosed'),

  };
},
error: function(error){
   alert("Error: " + error.code + " " + error.message);
}
  });
};

And my htm look like the following:

</ion-item class="more-list">
  <ion-item class="item more-item">
    <i class="icon-left ion-cash more-icon"></i>
    <p class="moredetails location"> {{Details.diagnosed}}</p>
  </ion-item>
  </ion-item>
</ion-list>

On that page, the data is rendered like this:

 [{"checked":true,"text":"Allergies"},{"checked":false,"text":"ADHD"},{"checked":false,"text":"Alcohol/Drug Dependence"},{"checked":false,"text":"Asthma"},{"checked":false,"text":"Autism"},{"checked":false,"text":"Cancer"},{"checked":false,"text":"Diabetes"},{"checked":false,"text":"Eating Disorder"},{"checked":false,"text":"Fertility Problems"},{"checked":false,"text":"Heart Disease"},{"checked":false,"text":"High Cholesterol"},{"checked":false,"text":"Menopause"},{"checked":false,"text":"Mood Disorders (e.g., anxiety, depression)"},{"checked":false,"text":"Obesity"},{"checked":false,"text":"Stroke"},{"checked":false,"text":"Prefer not to answer"}]

But how do I only display the values that have been checked as true?

Thank you in advance..

C array pointer arithmetic

I am trying to rewrite my code that takes the user input array, goes to the function and adds zeros between each number and saves it to array 2. My source code works just fine but I am having trouble trying to make it so that it uses pointer arithmetic just for the function to visit each array element, it cannot be sub scripting. What can you tell me about my code or suggestions on how to do this?

Source code:

#include <stdio.h>

void insert0(int n, int a1[], int a2[]);

int main(void) {

  int i;     
  int n;

  printf("Please enter the length of the input array: ");   
    scanf("%d", &n);

  int a[n];   
  int b[2*n];  

  printf("Enter %d numbers for the array: ", n);   
    for (i = 0; i < n; i++){     
      scanf("%d", &a[i]);
    }

  insert0(n, a,  b);

  printf("Output array:");   
    for (i = 0; i < 2*n; i++){
      printf(" %d", b[i]);   
        printf("n");
    }
    return 0; 
}

void insert0(int n, int a[], int b[]) {

  int i, j = 0; 

  for(i = 0; i < n; i++, j+=2){    
    b[j]= a[i];    
      b[j+1] = 0; 
  }
}

My arithmetic:

   #include <stdio.h>

    void insert0(int n, int *a1, int *a2);

    int main(void) {

      int i;     
      int n;

      printf("Please enter the length of the input array: ");   
        scanf("%d", &n);

      int a1[n];   
      int a2[2*n];  

      printf("Enter %d numbers for the array: ", n);   
        for (i = 0; i < n; i++){     
          scanf("%d", &a2[i]);
        }

//not sure if this is how you call it, I've seen it called with arr
      insert0(n, a1, a2); 

      printf("Output array:");   
        for (i = 0; i < 2*n; i++){
          printf(" %d", a2[i]);   
            printf("n");
        }
        return 0; 
    }

    void insert0(int n, int *a1, int *a2) {

      int *p;
      int j = 0;

        // I think I translated this properly     
        for(p = a1; p < a1+n; p++, j+=2){
          a2+j = a1+p;  
          //unsure how to get a2[j+1] to still work here with pointer  
            a2(j+1) = 0; 
      }
    }

C: Passing 2-dimensional array to function and using it [duplicate]

This question already has an answer here:

In a C program (to be compiled by Visual Studio 2013) I need to pass a pointer to a 1-dimensional array as a parameter of a function. The function writes values into the array. In another function I need to pass a two-dimensional array. This time the function does not need to write into the array - it just uses the values in it. I would like the functions to be usable with arrays of different sizes (i.e. I don't want to have to specify the number of elements (or in the case of the 2D array to number of sub-arrays of two elements each) in the array. I suppose I need to pass pointers to the arrays as parameters, but I'm not sure of the syntax for this, or the circumstances in which the array identifier can be used as a pointer to the array, or how this works for a 2D array.

How do I:

  1. Define the functions?
  2. Define the arrays that I am going to pass to the functions?
  3. Call the functions?
  4. Refer to elements of the arrays within the functions?

Everything I have tried so far has given errors of the form "'uchar **' differs in levels of indirection from 'uchar [1]'" or "different types for formal and actual parameter 3" or "'uchar ()[2]' differs in levels of indirection from 'uchar [16][2]'".

Here is some code:

int i2c_write(int device_addr, uchar *data[][], int bytes)
{
}

int i2c_read(int device_addr, int register_addr, uchar *data[], int bytes)
{
}

int main(void)
{
    uchar readbyte[1];
    uchar writedata[16][2];

    if (i2c_read(0x76, 0xD0, readbyte, 1))  
    { etc.
    }
    writedata[0][0] = 0xE0;
    writedata[0][1] = 0xB6;
    if (i2c_write(0x76, writedata, 1))
    { etc.
    }
}

save jquery value with php

i have form like this

<div id="signUp" class="form-inline">
   <div class="form-group">
      <label for="">I Sign up as</label>
      <input id="placehold" type="text" class="form-control text-center" readonly/>
      <div class="smallspace"></div>
      <div class="displayTable">
         <div class="radio-inline">
            <input type="radio" class="radio_item" value="Company"  name="item" id="radioCompany">
            <label class="label_item" for="radioCompany"></label>
            <p class="text-center colorGrey">Company</p>
         </div>
         <div class="radio-inline">
            <input type="radio" class="radio_item" value="Chef"  name="item" id="radioChef">
            <label class="label_item" for="radioChef"></label>
            <p class="text-center colorGrey">Chef</p>
         </div>
         <div class="radio-inline">
            <input type="radio" class="radio_item" value="Food lover" name="item" id="radioFoodLover">
            <label class="label_item" for="radioFoodLover"></label>
            <p class="text-center colorGrey">Food lover</p>
         </div>
      </div>
   </div>
</div>
<script src="js/upload.js"></script>

inside upload js i code like this

(function($) {
    "use strict";

    // register
    $(document).ready(function() {

        $('#signUp input').on('change', function() {
            var signUp = $(this).val();
            $("#placehold").val(signUp);//show value of chosen radio button to input text
        });
    });

})(jQuery);

summary this code is, i have input text(readonly) and 2 radio button, when we choose the radio button then system will get the value of the choosen than show it to the input type text.

the reason i put the validation to other file because honestly it got so much validation, for another input too. i just didnt like it if i have to place the validation inside html file.

my question is: is it posible to get that value and store it to database via PHP?

Grouping multidimensional php array by a key and add the values another key [duplicate]

Suppose I have following array:

Array
(
[2016] => Array
    (
        [C1] => Array
            (
                [0] => Array
                    (
                        [id] => 1
                        [project_id] => 1
                        [company_type] => C1
                        [capacity_share] => 12
                        [project_year] => 2016
                    )

                [1] => Array
                    (
                        [id] => 4
                        [project_id] => 2
                        [company_type] => C1
                        [capacity_share] => 16
                        [project_year] => 2016
                    )

            )

        [C2] => Array
            (
                [0] => Array
                    (
                        [id] => 2
                        [project_id] => 1
                        [company_type] => C2
                        [capacity_share] => 14
                        [project_year] => 2016
                    )

                [1] => Array
                    (
                        [id] => 3
                        [project_id] => 2
                        [company_type] => C2
                        [capacity_share] => 15
                        [project_year] => 2016
                    )

            )

    )

[2014] => Array
    (
        [C1] => Array
            (
                [0] => Array
                    (
                        [id] => 5
                        [project_id] => 3
                        [company_type] => C1
                        [capacity_share] => 20
                        [project_year] => 2014
                    )

                [1] => Array
                    (
                        [id] => 8
                        [project_id] => 4
                        [company_type] => C1
                        [capacity_share] => 10
                        [project_year] => 2014
                    )

            )

        [C2] => Array
            (
                [0] => Array
                    (
                        [id] => 6
                        [project_id] => 3
                        [company_type] => C2
                        [capacity_share] => 22
                        [project_year] => 2014
                    )

                [1] => Array
                    (
                        [id] => 7
                        [project_id] => 4
                        [company_type] => C2
                        [capacity_share] => 11
                        [project_year] => 2014
                    )

            )

    )

)

Is there any way so that I can create a new array like this:

Array
(
[0] => Array(
    //project_year
    'project_year' => 2016,          

     //sum of 'capacity_share' where company_type = C1 and project_year = 2016
    'C1_capacity_sum' => 28, //[12+16]

     //sum of 'capacity_share' where company_type = C2 and project_year = 2016
    'C2_capacity_sum' => 29 //[14+15]
    )
[1] => Array(
     //project_year
    'project_year' => 2014,

     //sum of 'capacity_share' where company_type = C1 and project_year = 2014
    'C1_capacity_sum' => 30, //[20+10]

     sum of 'capacity_share' where company_type = C2 and project_year = 2014
    'C2_capacity_sum' => 33 //[22+11]
    )
);

I am very new to PHP any can't find any built-in method for this. However I have tried my hands on array_walk and array_map.

I will welcome any hint or help regarding this.

Thanks.