问:
Can't connect my nodejs application with mLab database
I tried connecting it with mlab database but its not working, went through a lot of stackoverflow answers and tried everything but the errors are still there, please help.

```<code>var express = require('express');
var mongojs = require('mongojs');
var mongodb = require('mongodb');
// var db = mongojs('contactlist',['contactlist']);
var uri = 'mongodb://user:pass@####.mlab.com:13702/contactlist'
mongodb.MongoClient.connect(uri, { server: { auto_reconnect: true } }, function (err, contactlist) {

});

var db = mongodb.connect(uri);
var app = express();
var bodyParser = require('body-parser');
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());
app.get('/contactlist', function(req, res){
    console.log("I received a GET request");
    db.contactlist.find(function(err, docs){
        console.log(docs);
        res.json(docs);
    });
});

app.post('/contactlist', function(req, res) {
    console.log(req.body);
    db.contactlist.insert(req.body,function(err,doc) {
        res.json(doc);
    });
});
app.listen(process.env.PORT ||3000, function(){
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
</code>```

I am getting these errors after I try inserting data on the browser, its not even displaying the data from the database.
Errors:

```<code>TypeError: Cannot read property 'find' of undefined
        at D:\contactlistapp\server.js:17:16
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
        at next (D:\contactlistapp\node_modules\express\lib\router\route.js:137:13)
        at Route.dispatch (D:\contactlistapp\node_modules\express\lib\router\route.js:112:3)
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
        at D:\contactlistapp\node_modules\express\lib\router\index.js:281:22
        at Function.process_params (D:\contactlistapp\node_modules\express\lib\router\index.js:335:12)
        at next (D:\contactlistapp\node_modules\express\lib\router\index.js:275:10)
        at jsonParser (D:\contactlistapp\node_modules\body-parser\lib\types\json.js:103:7)
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
    { name: 'kkm', email: 'kmk' }
    TypeError: Cannot read property 'insert' of undefined
        at D:\contactlistapp\server.js:27:16
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
        at next
</code>```

答:
db.[collection_name] syntax ( ie. collection name on property ) is supported in MongoShell, but in node environment you must use following syntax:
db.collection("collection_name").find(). The same with insert.

Also note that connect function of MongoClient is async. You must get reference to database from callback that you specified.

```<code>mongodb.MongoClient.connect(uri, { server: { auto_reconnect: true } }, function (err, contactlist) {
     db = contactlist;
});
</code>```

Body:
I tried connecting it with mlab database but its not working, went through a lot of stackoverflow answers and tried everything but the errors are still there, please help.

var express = require('express');
var mongojs = require('mongojs');
var mongodb = require('mongodb');
// var db = mongojs('contactlist',['contactlist']);
var uri = 'mongodb://user:pass@####.mlab.com:13702/contactlist'
mongodb.MongoClient.connect(uri, { server: { auto_reconnect: true } }, function (err, contactlist) {

});

var db = mongodb.connect(uri);
var app = express();
var bodyParser = require('body-parser');
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());
app.get('/contactlist', function(req, res){
    console.log("I received a GET request");
    db.contactlist.find(function(err, docs){
        console.log(docs);
        res.json(docs);
    });
});

app.post('/contactlist', function(req, res) {
    console.log(req.body);
    db.contactlist.insert(req.body,function(err,doc) {
        res.json(doc);
    });
});
app.listen(process.env.PORT ||3000, function(){
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});

I am getting these errors after I try inserting data on the browser, its not even displaying the data from the database.
Errors:

TypeError: Cannot read property 'find' of undefined
        at D:\contactlistapp\server.js:17:16
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
        at next (D:\contactlistapp\node_modules\express\lib\router\route.js:137:13)
        at Route.dispatch (D:\contactlistapp\node_modules\express\lib\router\route.js:112:3)
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
        at D:\contactlistapp\node_modules\express\lib\router\index.js:281:22
        at Function.process_params (D:\contactlistapp\node_modules\express\lib\router\index.js:335:12)
        at next (D:\contactlistapp\node_modules\express\lib\router\index.js:275:10)
        at jsonParser (D:\contactlistapp\node_modules\body-parser\lib\types\json.js:103:7)
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
    { name: 'kkm', email: 'kmk' }
    TypeError: Cannot read property 'insert' of undefined
        at D:\contactlistapp\server.js:27:16
        at Layer.handle [as handle_request] (D:\contactlistapp\node_modules\express\lib\router\layer.js:95:5)
        at next

Body:
db.[collection_name] syntax ( ie. collection name on property ) is supported in MongoShell, but in node environment you must use following syntax:
db.collection("collection_name").find(). The same with insert.

Also note that connect function of MongoClient is async. You must get reference to database from callback that you specified.

mongodb.MongoClient.connect(uri, { server: { auto_reconnect: true } }, function (err, contactlist) {
     db = contactlist;
});


来源: stackexchange

问:
Displaying an alert on a new View Controller
I have a button that sends me on another View Controller. What I am trying is to display an alert on the next View Controller. </p>

答:
Swift 4

Create an extension of UIViewController with your function to display alert with required parameter arguments

```<code>extension UIViewController {

      func displayalert(title:String, message:String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction((UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in

            alert.dismiss(animated: true, completion: nil)

        })))

        self.present(alert, animated: true, completion: nil)

      }
}
</code>```

Now call this function from your view controller:

```<code>class TestViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.displayalert(title: <String>, message: <String>)
    }
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Swift 4

Create an extension of UIViewController with your function to display alert with required parameter arguments

extension UIViewController {

      func displayalert(title:String, message:String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction((UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in

            alert.dismiss(animated: true, completion: nil)

        })))

        self.present(alert, animated: true, completion: nil)

      }
}

Now call this function from your view controller:

class TestViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.displayalert(title: <String>, message: <String>)
    }
}


问:
How can I create directly my own rss.xml in OctoberCMS?
I want to generate rss.xml file in OctoberCMS by manually. Other plugins cannot be customized what I want. How can generate it by my own hand? Any suggestion?</p>

答:
You could use the File::put method to place an XML file within the theme assets public folder.

```<code>File::put(themes_path('mytheme/assets/somefile.xml'), $xmlContents);
</code>```

Body:
You could use the File::put method to place an XML file within the theme assets public folder.

File::put(themes_path('mytheme/assets/somefile.xml'), $xmlContents);


问:
MySQL CASE WHEN within CASE WHEN
Cars

```<code>Make  |  Model  |  Year   |  Color
Honda |  Accord |  12     |  Red
Lexus |    IS   |  14     |  Blue
</code>```

I receive files like these and have to make the sure header row matches the parameters before I send it off to a php script.

I currently have a SELECT CASE WHEN that checks for other errors such as blanks in the code:

```<code>SELECT
CASE
WHEN a.Make = '' THEN '**BLANK**'
ELSE a.Make
END as Make,
</code>```

Is it possible that there's a SELECT within SELECT that I can use to make sure the received files header (and only header) matches our headers?

答:
maybe you should try something like : </p>

```<code>SET @make := (SELECT a.Make FROM cars a WHERE ...);
SET @model := (SELECT a.Model FROM cars a WHERE ...);

IF @make = 'Make' AND @model = 'Model' AND ... THEN
#continue your script
ELSE
#end your script
END IF;
</code>```

Title: MySQL CASE WHEN within CASE WHEN

Body:
Cars

Make  |  Model  |  Year   |  Color
Honda |  Accord |  12     |  Red
Lexus |    IS   |  14     |  Blue

I receive files like these and have to make the sure header row matches the parameters before I send it off to a php script.

I currently have a SELECT CASE WHEN that checks for other errors such as blanks in the code:

SELECT
CASE
WHEN a.Make = '' THEN '**BLANK**'
ELSE a.Make
END as Make,

Is it possible that there's a SELECT within SELECT that I can use to make sure the received files header (and only header) matches our headers?

Body:
maybe you should try something like :

SET @make := (SELECT a.Make FROM cars a WHERE ...);
SET @model := (SELECT a.Model FROM cars a WHERE ...);

IF @make = 'Make' AND @model = 'Model' AND ... THEN
#continue your script
ELSE
#end your script
END IF;


问:
How to embed a tweet from Twitter which is also AMP valid?
I want to embed a tweet from Twitter in my WordPress blog. I recently made the AMP version of the website.

But, the embed codes for AMP and non-AMP pages are different. But, I have one post editor at WordPress for both versions of the website. How to achieve this thing?

答:
Check this guide out. The first example is exactly how to embed Tweets.

You need to embed the library on your page:

```<code><script async custom-element="amp-twitter"
  src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js"></script>
</code>```

Then, you can add as many tweets as you want. Just change the attribute: data-tweetid for the id of the tweet to embed.

```<code><amp-twitter width="390" height="50"
    layout="responsive"
    data-tweetid="638793490521001985">
</amp-twitter>
</code>```

See a github example.

PS: If you do not like how it works, you can always use an iframe and then use another HTML page to do whatever you want there; but I would definitely encourage you to use the library that AMP provides.

Body:
Check this guide out. The first example is exactly how to embed Tweets.

You need to embed the library on your page:

<script async custom-element="amp-twitter"
  src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js"></script>

Then, you can add as many tweets as you want. Just change the attribute: data-tweetid for the id of the tweet to embed.

<amp-twitter width="390" height="50"
    layout="responsive"
    data-tweetid="638793490521001985">
</amp-twitter>

See a github example.

PS: If you do not like how it works, you can always use an iframe and then use another HTML page to do whatever you want there; but I would definitely encourage you to use the library that AMP provides.


问:
Scheduling of GNURadio [general_] work function for custom source block
I'm trying to implement a GNURadio source block in Python, which has to produce a vector of a fixed size at each call of the [general_] work function.

As a first toy-example I tried to output just a vector of constant values which should change at each call of the [general_] work function.

```<code>import numpy
import sys
from gnuradio import gr

class my_source_vf(gr.sync_block):
    """
    docstring for block
    """
    def __init__(self, v_size):
        self.v_size = v_size
        self.mult = 1
        self.buff = numpy.ones(v_size)
        gr.sync_block.__init__(self,
            name="my_source_vf",
            in_sig=None,
            #out_sig=[numpy.float32])
            out_sig=[(numpy.float32, self.v_size)])

    def work(self, input_items, output_items):
        # <+signal processing here+>
        print len(output_items)

        out = output_items[0]
        out[0][:] = self.buff*self.mult
        self.mult = self.mult+1

        return self.v_size
</code>```

However, when I connect it to QT GUI Vector sink block I just see oscillations between 0 and 1, which let me think [general_] work function is called just once.

答: You mustn't return v_size – that's the length of one item, but you should return the number of items you've produced this call.

Body:
I'm trying to implement a GNURadio source block in Python, which has to produce a vector of a fixed size at each call of the [general_] work function.

As a first toy-example I tried to output just a vector of constant values which should change at each call of the [general_] work function.

import numpy
import sys
from gnuradio import gr

class my_source_vf(gr.sync_block):
    """
    docstring for block
    """
    def __init__(self, v_size):
        self.v_size = v_size
        self.mult = 1
        self.buff = numpy.ones(v_size)
        gr.sync_block.__init__(self,
            name="my_source_vf",
            in_sig=None,
            #out_sig=[numpy.float32])
            out_sig=[(numpy.float32, self.v_size)])

    def work(self, input_items, output_items):
        # <+signal processing here+>
        print len(output_items)

        out = output_items[0]
        out[0][:] = self.buff*self.mult
        self.mult = self.mult+1

        return self.v_size

However, when I connect it to QT GUI Vector sink block I just see oscillations between 0 and 1, which let me think [general_] work function is called just once.


问:
Resize then crop PHP
Ok, basically I want all images to be 170x170px squares.
Thus if an image is not a square i want it to be resized, and then cropped in the middle..

I have spent numerous hours playing with this and I am getting nowhere.. I have gotten it to crop a section of the bigger image etc, but i specifically need the image to be resized, then cropped..

Any help would be greatly appreciated.

```<code>// get image size of img
$x = @getimagesize($img);
// image width
$sw = $x[0];
// image height
$sh = $x[1];

if($sw > $sh) // Horizontal Rectangle?
{
  $newwidth = ($sw/$sh)*170;
  $newheight=170;
  $x_pos = ($sw - $sh) / 2;
  $x_pos = ceil($x_pos);
  $y_pos=0;
}

else if($sh > $sw) // Vertical Rectangle?
{
  $newheight = ($sh/$sw)*170;
  $newwidth=170;
  $y_pos = ($sh - $sw) / 2;
  $y_pos = ceil($y_pos);
  $x_pos=0;
}
else //Already Square
{
  $newheight=170;
  $newwidth=170;
}

$im = @ImageCreateFromJPEG ($img) or // Read JPEG Image
$im = @ImageCreateFromPNG ($img) or // or PNG Image
$im = @ImageCreateFromGIF ($img) or // or GIF Image
$im = false; // If image is not JPEG, PNG, or GIF

if (!$im) {
  // We get errors from PHP's ImageCreate functions...
  // So let's echo back the contents of the actual image.
  readfile ($img);
} else {
  // Create the resized image destination
  $thumb = @ImageCreateTrueColor (170, 170);
  // Copy from image source, resize it, and paste to image destination
  imagecopyresampled($thumb, $im, 0, 0, 180, $y_pos, 170, 170, $newwidth,
    $newheight);
}
</code>```

答:
Are you using ImageMagic? If not, you should.
http://php.net/manual/en/book.imagick.php</p>

ContentLicense: CC BY-SA 2.5

Title: Resize then crop PHP

Body:
Ok, basically I want all images to be 170x170px squares.
Thus if an image is not a square i want it to be resized, and then cropped in the middle..

I have spent numerous hours playing with this and I am getting nowhere.. I have gotten it to crop a section of the bigger image etc, but i specifically need the image to be resized, then cropped..

Any help would be greatly appreciated.

// get image size of img
$x = @getimagesize($img);
// image width
$sw = $x[0];
// image height
$sh = $x[1];

if($sw > $sh) // Horizontal Rectangle?
{
  $newwidth = ($sw/$sh)*170;
  $newheight=170;
  $x_pos = ($sw - $sh) / 2;
  $x_pos = ceil($x_pos);
  $y_pos=0;
}

else if($sh > $sw) // Vertical Rectangle?
{
  $newheight = ($sh/$sw)*170;
  $newwidth=170;
  $y_pos = ($sh - $sw) / 2;
  $y_pos = ceil($y_pos);
  $x_pos=0;
}
else //Already Square
{
  $newheight=170;
  $newwidth=170;
}

$im = @ImageCreateFromJPEG ($img) or // Read JPEG Image
$im = @ImageCreateFromPNG ($img) or // or PNG Image
$im = @ImageCreateFromGIF ($img) or // or GIF Image
$im = false; // If image is not JPEG, PNG, or GIF

if (!$im) {
  // We get errors from PHP's ImageCreate functions...
  // So let's echo back the contents of the actual image.
  readfile ($img);
} else {
  // Create the resized image destination
  $thumb = @ImageCreateTrueColor (170, 170);
  // Copy from image source, resize it, and paste to image destination
  imagecopyresampled($thumb, $im, 0, 0, 180, $y_pos, 170, 170, $newwidth,
    $newheight);
}


问:
Using Google Daydream keyboard in VR mode for text input in canvas(for Daydream app)
Recently, I have seen many posts about changes in Google daydream keyboard App. I have a login scene in my daydream app. Right now, I show that scene in non-VR mode, as I don't have a way to show keyboard in VR mode. Is there a way to use daydream keyboard in my Daydream app(VR mode), so that I can put that login canvas scene in VR mode? I have seen earlier post like this saying it can't be done till now. But now, as there are new updates, can someone please help me out?</p>

答: Yes, now you can use the daydream keyboard (used in YouTube Daydream app). The GoogleVR SDK now provides the prefab for the keyboard too. Download the GoogleVR SDK, under the directory Demos/Scenes, you will find the demo for Keyboard. Enjoy!!!</p>


问:
How to set alpha on UIButton's label subviews
I want to programmatically set multiple alignment combinations for my button title, like so:

The easiest way I found to do this was to add two UILabels as subviews of my custom UIButton and set autolayout constraints accordingly.

However, I can't figure out how to make my labels behave the same way as a button title would (namely having its alpha altered when a button tap occurs).

I have tried setting their alpha property in a target-action method for .touchUpInside but since they're not attached to the button state, they won't change their alpha back to normal when the user ends tapping the button.

```<code>class Button: UIView {

var leftButton = UIButton(type: .roundedRect)
var rightButton = UIButton(type: .roundedRect)

init() {
    super.init(frame: .zero)
    createButton()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    createButton()
}

func createButton() {
    self.backgroundColor = UIColor.cyan
    self.layer.borderWidth = 0.5
    self.layer.borderColor = UIColor.blue.cgColor
    self.addSubview(leftButton)
    self.addSubview(rightButton)

    leftButton.setTitle("left", for: .normal)
    leftButton.setTitleColor(UIColor.black, for: .normal)
    leftButton.layer.borderColor = UIColor.yellow.cgColor
    leftButton.layer.borderWidth = 0.5
    leftButton.translatesAutoresizingMaskIntoConstraints = false
    leftButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
    leftButton.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
    leftButton.trailingAnchor.constraint(lessThanOrEqualTo: rightButton.leadingAnchor).isActive = true
    leftButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true

    rightButton.setTitle("right", for: .normal)
    rightButton.layer.borderColor = UIColor.green.cgColor
    rightButton.layer.borderWidth = 0.5
    rightButton.setTitleColor(UIColor.black, for: .normal)
    rightButton.translatesAutoresizingMaskIntoConstraints = false
    rightButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
    rightButton.leadingAnchor.constraint(greaterThanOrEqualTo: leftButton.trailingAnchor).isActive = true
    rightButton.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
    rightButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true

    leftButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    rightButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

func buttonTapped() {
    print("button tapped")
}
</code>```

答:
What you need is to differentiate between tap and hold and release of the button states. Luckily there are 2 built-in action methods that we can make use of for this.

Touch Down Action: This will be called as soon as you tap on the button. So you can change the alpha of your labels here.

Touch Up Inside: This action method is called when you have released the button. So you can reset your alpha here.

```<code>@IBAction func touchupInsideAction(_ sender: Any) {

    firstLabel.alpha = 1.0
    secondLabel.alpha = 1.0
}

@IBAction func touchDownAction(_ sender: Any) {

    firstLabel.alpha = 0.5
    secondLabel.alpha = 0.5

}
</code>```

Body:
I want to programmatically set multiple alignment combinations for my button title, like so:

The easiest way I found to do this was to add two UILabels as subviews of my custom UIButton and set autolayout constraints accordingly.

However, I can't figure out how to make my labels behave the same way as a button title would (namely having its alpha altered when a button tap occurs).

I have tried setting their alpha property in a target-action method for .touchUpInside but since they're not attached to the button state, they won't change their alpha back to normal when the user ends tapping the button.

class Button: UIView {

var leftButton = UIButton(type: .roundedRect)
var rightButton = UIButton(type: .roundedRect)

init() {
    super.init(frame: .zero)
    createButton()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    createButton()
}

func createButton() {
    self.backgroundColor = UIColor.cyan
    self.layer.borderWidth = 0.5
    self.layer.borderColor = UIColor.blue.cgColor
    self.addSubview(leftButton)
    self.addSubview(rightButton)

    leftButton.setTitle("left", for: .normal)
    leftButton.setTitleColor(UIColor.black, for: .normal)
    leftButton.layer.borderColor = UIColor.yellow.cgColor
    leftButton.layer.borderWidth = 0.5
    leftButton.translatesAutoresizingMaskIntoConstraints = false
    leftButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
    leftButton.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true
    leftButton.trailingAnchor.constraint(lessThanOrEqualTo: rightButton.leadingAnchor).isActive = true
    leftButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true

    rightButton.setTitle("right", for: .normal)
    rightButton.layer.borderColor = UIColor.green.cgColor
    rightButton.layer.borderWidth = 0.5
    rightButton.setTitleColor(UIColor.black, for: .normal)
    rightButton.translatesAutoresizingMaskIntoConstraints = false
    rightButton.topAnchor.constraint(equalTo: self.topAnchor, constant: 0).isActive = true
    rightButton.leadingAnchor.constraint(greaterThanOrEqualTo: leftButton.trailingAnchor).isActive = true
    rightButton.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true
    rightButton.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: 0).isActive = true

    leftButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
    rightButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}

func buttonTapped() {
    print("button tapped")
}

Body:
What you need is to differentiate between tap and hold and release of the button states. Luckily there are 2 built-in action methods that we can make use of for this.

Touch Down Action: This will be called as soon as you tap on the button. So you can change the alpha of your labels here.

Touch Up Inside: This action method is called when you have released the button. So you can reset your alpha here.

@IBAction func touchupInsideAction(_ sender: Any) {

    firstLabel.alpha = 1.0
    secondLabel.alpha = 1.0
}

@IBAction func touchDownAction(_ sender: Any) {

    firstLabel.alpha = 0.5
    secondLabel.alpha = 0.5

}


问:
How to select specific row column pairs in numpy array which have specific value?
I am trying to have a numpy array with random numbers from 0 to 1:

```<code>import numpy as np
x = np.random.random((3,3))
</code>```

yields

```<code>[[ 0.11874238  0.71885484  0.33656161]
 [ 0.69432263  0.25234083  0.66118676]
 [ 0.77542651  0.71230397  0.76212491]]
</code>```

And, from this array, I need the row,column combinations which have values bigger than 0.3. So the expected output should look like:

```<code>(0,1),(0,2),(1,0),(1,2),(2,0),(2,1),(2,2)
</code>```

To be able to extract the item (the values of x[row][column]),and tried to write the output to a file. I tried the following command:

```<code>with open('newfile.txt', 'w') as fd:
    for row in x:
        for item in row:
            if item > 0.3:
                print(item)
                for row in item:
                    for col in item:
                        print(row,column,'\n')
                        fd.write(row,column,'\n')
</code>```

However, it raises an error :

```<code>TypeError: 'numpy.float64' object is not iterable
</code>```

Also, I searched but could not find how to start the numpy index from 1 instead of 0. For example, the expected output would look like this:

```<code> (1,2),(1,3),(2,1),(2,3),(3,1),(3,2),(3,3)
</code>```

Do you know how to get these outputs?

答:
You could use np.where, which returns two arrays (when applied to a 2D array), with indices of rows (and corresponding columns) satisfy the condition you specifiy as an argument.
Then you can zip these two arrays to get back a list of tuples:

```<code>list(zip(*np.where(x > 0.3)))
</code>```

If you want to add 1 to every element of every tuple (use 1 based indexing), either loop over the tuples, either add 1 to each array returned by where:

```<code>res = np.where(x > 0.3)
res[0] += 1  # adds one to every element of res[0] thanks to broadcasting
res[1] += 1
list(zip(*res))
</code>```

Body:
I am trying to have a numpy array with random numbers from 0 to 1:

import numpy as np
x = np.random.random((3,3))

yields

[[ 0.11874238  0.71885484  0.33656161]
 [ 0.69432263  0.25234083  0.66118676]
 [ 0.77542651  0.71230397  0.76212491]]

And, from this array, I need the row,column combinations which have values bigger than 0.3. So the expected output should look like:

(0,1),(0,2),(1,0),(1,2),(2,0),(2,1),(2,2)

To be able to extract the item (the values of x[row][column]),and tried to write the output to a file. I tried the following command:

with open('newfile.txt', 'w') as fd:
    for row in x:
        for item in row:
            if item > 0.3:
                print(item)
                for row in item:
                    for col in item:
                        print(row,column,'\n')
                        fd.write(row,column,'\n')

However, it raises an error :

TypeError: 'numpy.float64' object is not iterable

Also, I searched but could not find how to start the numpy index from 1 instead of 0. For example, the expected output would look like this:

 (1,2),(1,3),(2,1),(2,3),(3,1),(3,2),(3,3)

Do you know how to get these outputs?

Body:
You could use np.where, which returns two arrays (when applied to a 2D array), with indices of rows (and corresponding columns) satisfy the condition you specifiy as an argument.
Then you can zip these two arrays to get back a list of tuples:

list(zip(*np.where(x > 0.3)))

If you want to add 1 to every element of every tuple (use 1 based indexing), either loop over the tuples, either add 1 to each array returned by where:

res = np.where(x > 0.3)
res[0] += 1  # adds one to every element of res[0] thanks to broadcasting
res[1] += 1
list(zip(*res))


问:
Excel VBA - loop over files in folder, copy range, paste in this workbook
I have 500 excel files with data. I would merge all this data into one file.

Task list to achieve this:

I want to loop over all the files in a folder

open the file,

copy this range "B3:I102"

paste it into the 1st sheet of the active workbook

repeat but paste new data underneath

I've done task 1-4 but i need help with task 5, last bit - pasting the data under the existing data and making it dynamic. I've highlighted this bit with '#### in my code.

Here is my code which I've put together from other people's question :)

Any suggestions on how to do this?

```<code>Sub LoopThroughFiles()
Dim MyObj As Object,
MySource As Object,
file As Variant
Dim wbThis                  As Workbook     'workbook where the data is to be pasted, aka Master file
Dim wbTarget                As Workbook     'workbook from where the data is to be copied from, aka Overnights file
Dim LastRow As Long
Dim sht1 As Worksheet
Dim sht2 As Worksheet

'set to the current active workbook (the source book, the Master!)
Set wbThis = ActiveWorkbook
Set sht1 = wbThis.Sheets("Sheet1")

Folder = "\\dne\ldc\research-dept\3 CEEMEA\15. EMB\Turkey\TLC Overnight & Weekly Reports\weekly (majeed)\"
Fname = Dir(Folder)

While (Fname <> "")

  Set wbTarget = Workbooks.Open(Filename:=Folder & Fname)
  wbTarget.Activate
  Range("b3:i102").Copy

  wbThis.Activate

  '################################
  'NEED HELP HERE. I GET A ERROR HERE. NEEDS TO BE MORE DYNAMIC.
  sht1.Range("b1:i100").PasteSpecial

 Fname = Dir

 'close the overnight's file
  wbTarget.Close
 Wend

End Sub
</code>```

答:
Why don't you place a counter? Like this:

```<code>Dim counter As Long
counter = 1
</code>```

And then:

```<code>While (Fname <> "")

      Set wbTarget = Workbooks.Open(Filename:=Folder & Fname)
      wbTarget.Activate
      Range("b3:i102").Copy

      wbThis.Activate

      'Solution:

      sht1.Range("b" & counter & ":i" & counter + 99).PasteSpecial
      counter = counter + 100

      Fname = Dir

     'close the overnight's file
     wbTarget.Close
Wend
</code>```

Body:
I have 500 excel files with data. I would merge all this data into one file.

Task list to achieve this:

I want to loop over all the files in a folder

open the file,

copy this range "B3:I102"

paste it into the 1st sheet of the active workbook

repeat but paste new data underneath

I've done task 1-4 but i need help with task 5, last bit - pasting the data under the existing data and making it dynamic. I've highlighted this bit with '#### in my code.

Here is my code which I've put together from other people's question :)

Any suggestions on how to do this?

Sub LoopThroughFiles()
Dim MyObj As Object,
MySource As Object,
file As Variant
Dim wbThis                  As Workbook     'workbook where the data is to be pasted, aka Master file
Dim wbTarget                As Workbook     'workbook from where the data is to be copied from, aka Overnights file
Dim LastRow As Long
Dim sht1 As Worksheet
Dim sht2 As Worksheet

'set to the current active workbook (the source book, the Master!)
Set wbThis = ActiveWorkbook
Set sht1 = wbThis.Sheets("Sheet1")

Folder = "\\dne\ldc\research-dept\3 CEEMEA\15. EMB\Turkey\TLC Overnight & Weekly Reports\weekly (majeed)\"
Fname = Dir(Folder)

While (Fname <> "")

  Set wbTarget = Workbooks.Open(Filename:=Folder & Fname)
  wbTarget.Activate
  Range("b3:i102").Copy

  wbThis.Activate

  '################################
  'NEED HELP HERE. I GET A ERROR HERE. NEEDS TO BE MORE DYNAMIC.
  sht1.Range("b1:i100").PasteSpecial

 Fname = Dir

 'close the overnight's file
  wbTarget.Close
 Wend

End Sub

Body:
Why don't you place a counter? Like this:

Dim counter As Long
counter = 1

And then:

While (Fname <> "")

      Set wbTarget = Workbooks.Open(Filename:=Folder & Fname)
      wbTarget.Activate
      Range("b3:i102").Copy

      wbThis.Activate

      'Solution:

      sht1.Range("b" & counter & ":i" & counter + 99).PasteSpecial
      counter = counter + 100

      Fname = Dir

     'close the overnight's file
     wbTarget.Close
Wend


问:
A PHP Error was encountered Severity: Notice Message: Undefined variable: result

A PHP Error was encountered Severity: Notice

Message: Undefined variable: result

Filename: user/messages.php

Line Number: 87

Backtrace:

File: E:\xampp\htdocs\ci\application\views\user\messages.php Line: 87
  Function: _error_handler

File: E:\xampp\htdocs\ci\application\controllers\users\Dashboard.php
  Line: 12 Function: view

File: E:\xampp\htdocs\ci\index.php Line: 315 Function: require_once

here is my code
Controller

```<code>      <?php defined('BASEPATH') OR exit('No direct script access allowed');
        class Bills extends CI_Controller{
       function __construct(){
      parent::__construct();
     }

     public function bill(){
     $id = $this->session->userdata('email');
     $this->load->database();
     $this->load->helper(array('form', 'url', 'html'));
     $this->load->model('fuser/Bill');
     $data['result'] = $this->Bill->bills();
     $this->load->view('user/messages',$data);
      }
      }
      ?>

**Model**

      <?php
     class Bill extends CI_Model
     {
      function __construct()
      {
         // Call the Model constructor
         parent::__construct();
      }
      //we will use the select function
      public function bills($id)
      {
         //data is retrive from this query

     $query = $this->db->get('invoices');
       return $query->result();
      }

      }
     ?>

**View**
      <div class="billing_tabs_text_part">
                <?php foreach($result as $row){?>
                  <p><?php echo $row['book_id']; }?></p>
                </div>
</code>```

答:
i am not sure which section is your problem so i suggest something how to find error

```<code>public function bill()
{
    echo 'ok'; // check controller work
    $id = $this->session->userdata('email');
    $this->load->database();
    echo 'ok1';
    $this->load->helper(array('form', 'url', 'html'));
    echo 'ok2';
    /*$this->load->model('fuser/Bill');
    $data['result'] = $this->Bill->bills();
    $this->load->view('user/messages', $data);*/
}
</code>```

if this is print ok, ok1 , ok2 then this is query problem , if no print ok,ok1 then this is not query problem

in this case try to find error, if other ok then must print ok

```<code>public function bill()
{
    echo 'ok';
    /*$id = $this->session->userdata('email');
    $this->load->database();
    $this->load->helper(array('form', 'url', 'html'));
    $this->load->model('fuser/Bill');
    $data['result'] = $this->Bill->bills();
    $this->load->view('user/messages', $data);*/
}
</code>```

Body:
A PHP Error was encountered Severity: Notice

Message: Undefined variable: result

Filename: user/messages.php

Line Number: 87

Backtrace:

File: E:\xampp\htdocs\ci\application\views\user\messages.php Line: 87
  Function: _error_handler

File: E:\xampp\htdocs\ci\application\controllers\users\Dashboard.php
  Line: 12 Function: view

File: E:\xampp\htdocs\ci\index.php Line: 315 Function: require_once

here is my code
Controller

      <?php defined('BASEPATH') OR exit('No direct script access allowed');
        class Bills extends CI_Controller{
       function __construct(){
      parent::__construct();
     }

     public function bill(){
     $id = $this->session->userdata('email');
     $this->load->database();
     $this->load->helper(array('form', 'url', 'html'));
     $this->load->model('fuser/Bill');
     $data['result'] = $this->Bill->bills();
     $this->load->view('user/messages',$data);
      }
      }
      ?>

**Model**

      <?php
     class Bill extends CI_Model
     {
      function __construct()
      {
         // Call the Model constructor
         parent::__construct();
      }
      //we will use the select function
      public function bills($id)
      {
         //data is retrive from this query

     $query = $this->db->get('invoices');
       return $query->result();
      }

      }
     ?>

**View**

                <?php foreach($result as $row){?>

<?php echo $row['book_id']; }?>

Body:
i am not sure which section is your problem so i suggest something how to find error

public function bill()
{
    echo 'ok'; // check controller work
    $id = $this->session->userdata('email');
    $this->load->database();
    echo 'ok1';
    $this->load->helper(array('form', 'url', 'html'));
    echo 'ok2';
    /*$this->load->model('fuser/Bill');
    $data['result'] = $this->Bill->bills();
    $this->load->view('user/messages', $data);*/
}

if this is print ok, ok1 , ok2 then this is query problem , if no print ok,ok1 then this is not query problem

in this case try to find error, if other ok then must print ok

public function bill()
{
    echo 'ok';
    /*$id = $this->session->userdata('email');
    $this->load->database();
    $this->load->helper(array('form', 'url', 'html'));
    $this->load->model('fuser/Bill');
    $data['result'] = $this->Bill->bills();
    $this->load->view('user/messages', $data);*/
}


问:
Is now the time to start designing for 1280px wide screens instead of 1024px?
Need opinions on this, what do you guys think? A good idea or not so good idea.

I could do a seperate css style but not sure whether to drop 1024 for sure.

答:
Whenever someone asks me this type of questions I always say..

It depends on your audience. Try using trackig tools like Google Analytics to see what resolution/browser versions your users are using and then change it to suit the majority of the users.


问:
Cocos2d js (Cocos2d x 3.14) on android with deepstream io
Have anyone use cocos2d js with deepstream io ?

I tried to use deepstream client js but it seem to be fail when try to connect server via network (websocket) :

this is adb log:

06-06 09:43:19.227: D/cocos2d-x debug info(26288): connectDeepStream
  [object Object]
  PlayerActions.login.request@assets/src/modules/Actions/Player.js:22:13,

06-06 09:43:19.232: D/WebSocket.cpp(26288): WebSocket thread start,
  helper instance: 0x97987760

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: Initial logging
  level 911

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: Libwebsockets
  version: 2.1.0 james@James-Chen.local-v3.4-139-gbdcf7f8

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: IPV6 compiled in
  and enabled

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: libev support not
  compiled in

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: libuv support not
  compiled in

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE:  Threads: 1 each
  1024 fds

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE:  mem: platform fd
  map:  4096 bytes

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE:  Compiled with
  OpenSSL support

06-06 09:43:19.247: D/WebSocket.cpp(26288): NOTICE:  mem: per-conn:

  376 bytes + protocol rx buf

06-06 09:43:19.247: D/WebSocket.cpp(26288): protocol: ws, host:
  ...*, port: 3512, path: deepstream

06-06 09:43:19.247: D/WebSocket.cpp(26288): NOTICE: Creating Vhost
  'default' port -1, 1 protocols, IPv6 on

06-06 09:43:19.252: D/WebSocket.cpp(26288): NOTICE: lws_protocol_init

06-06 09:43:19.252: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 32

06-06 09:43:19.252: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 29

06-06 09:43:19.257: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 24

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionError, state: 0 ...

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionClosed, state: 2 ...

06-06 09:43:19.267: D/WebSocket.cpp(26288): onConnectionClosed,
  WebSocket (0xae824ed0) is closing by server.

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionClosed DONE!

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 45

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 33

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionClosed, state: 3 ...

06-06 09:43:19.282: D/cocos2d-x debug info(26288): _onError  [object
  Object] object

06-06 09:43:19.282: D/cocos2d-x debug info(26288): [object Object]

06-06 09:43:19.282: D/cocos2d-x debug info(26288): {"type":"error"}

06-06 09:43:19.287: D/WebSocket.cpp(26288): In the destructor of
  WebSocket (0xae824ed0)

06-06 09:43:19.287: D/WebSocket.cpp(26288): before join ws thread

06-06 09:43:19.292: D/WebSocket.cpp(26288): NOTICE:
  lws_context_destroy

06-06 09:43:19.292: D/WebSocket.cpp(26288): WebSocket thread exit,
  helper instance: 0x97987760

06-06 09:43:19.292: D/WebSocket.cpp(26288): after join ws thread

06-06 09:43:19.317: D/cocos2d-x debug info(26288): C connectionError
  [object Object] string

06-06 09:43:19.317: D/cocos2d-x debug info(26288): error: string

06-06 09:43:19.317: D/cocos2d-x debug info(26288): [object Object]

06-06 09:43:19.317: D/cocos2d-x debug info(26288): connectionError

06-06 09:43:19.317: D/cocos2d-x debug info(26288): C

i tried to log content of error , but it is only "{"type":"error"}" .

Code is so simple . I only start a deepstream server and try to login to server on android client (js cocos2d-js)

like this :

```<code>this.client = deepstream(CCDefine.DeepStreamServer).login({username: arg.username, password: arg.password},function(success,data){

cc.log(success,data)

        if(success){
            cc.log('Deep stream connect success')

        }else{
            cc.log('Deep stream connect false')
        }
    })
</code>```

I find out that cocos use libwebsockets without libuv while deepstream use that . can it problem ? I tried to compile libwebsockets with libuv for android but i failed.

Now i currently resolve this problem by use deepstream java SDK , and make a bridge from java to js.
Thank u all.

答:
It's hard to tell what the issue is here, but it looks like the WebSocket API could be incompatible.
Could you try logging the contents of the error object in the deepstream error handler? If you could post a small code sample that would be great too.</p>

ContentLicense: CC BY-SA 4.0

Body:
Have anyone use cocos2d js with deepstream io ?

I tried to use deepstream client js but it seem to be fail when try to connect server via network (websocket) :

this is adb log:

06-06 09:43:19.227: D/cocos2d-x debug info(26288): connectDeepStream
  [object Object]
  PlayerActions.login.request@assets/src/modules/Actions/Player.js:22:13,

06-06 09:43:19.232: D/WebSocket.cpp(26288): WebSocket thread start,
  helper instance: 0x97987760

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: Initial logging
  level 911

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: Libwebsockets
  version: 2.1.0 james@James-Chen.local-v3.4-139-gbdcf7f8

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: IPV6 compiled in
  and enabled

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: libev support not
  compiled in

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE: libuv support not
  compiled in

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE:  Threads: 1 each
  1024 fds

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE:  mem: platform fd
  map:  4096 bytes

06-06 09:43:19.237: D/WebSocket.cpp(26288): NOTICE:  Compiled with
  OpenSSL support

06-06 09:43:19.247: D/WebSocket.cpp(26288): NOTICE:  mem: per-conn:

  376 bytes + protocol rx buf

06-06 09:43:19.247: D/WebSocket.cpp(26288): protocol: ws, host:
  ...*, port: 3512, path: deepstream

06-06 09:43:19.247: D/WebSocket.cpp(26288): NOTICE: Creating Vhost
  'default' port -1, 1 protocols, IPv6 on

06-06 09:43:19.252: D/WebSocket.cpp(26288): NOTICE: lws_protocol_init

06-06 09:43:19.252: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 32

06-06 09:43:19.252: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 29

06-06 09:43:19.257: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 24

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionError, state: 0 ...

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionClosed, state: 2 ...

06-06 09:43:19.267: D/WebSocket.cpp(26288): onConnectionClosed,
  WebSocket (0xae824ed0) is closing by server.

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionClosed DONE!

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 45

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  Unhandled websocket event: 33

06-06 09:43:19.267: D/WebSocket.cpp(26288): WebSocket (0xae824ed0)
  onConnectionClosed, state: 3 ...

06-06 09:43:19.282: D/cocos2d-x debug info(26288): _onError  [object
  Object] object

06-06 09:43:19.282: D/cocos2d-x debug info(26288): [object Object]

06-06 09:43:19.282: D/cocos2d-x debug info(26288): {"type":"error"}

06-06 09:43:19.287: D/WebSocket.cpp(26288): In the destructor of
  WebSocket (0xae824ed0)

06-06 09:43:19.287: D/WebSocket.cpp(26288): before join ws thread

06-06 09:43:19.292: D/WebSocket.cpp(26288): NOTICE:
  lws_context_destroy

06-06 09:43:19.292: D/WebSocket.cpp(26288): WebSocket thread exit,
  helper instance: 0x97987760

06-06 09:43:19.292: D/WebSocket.cpp(26288): after join ws thread

06-06 09:43:19.317: D/cocos2d-x debug info(26288): C connectionError
  [object Object] string

06-06 09:43:19.317: D/cocos2d-x debug info(26288): error: string

06-06 09:43:19.317: D/cocos2d-x debug info(26288): [object Object]

06-06 09:43:19.317: D/cocos2d-x debug info(26288): connectionError

06-06 09:43:19.317: D/cocos2d-x debug info(26288): C

i tried to log content of error , but it is only "{"type":"error"}" .

Code is so simple . I only start a deepstream server and try to login to server on android client (js cocos2d-js)

like this :

this.client = deepstream(CCDefine.DeepStreamServer).login({username: arg.username, password: arg.password},function(success,data){

cc.log(success,data)

        if(success){
            cc.log('Deep stream connect success')

        }else{
            cc.log('Deep stream connect false')
        }
    })

I find out that cocos use libwebsockets without libuv while deepstream use that . can it problem ? I tried to compile libwebsockets with libuv for android but i failed.

Now i currently resolve this problem by use deepstream java SDK , and make a bridge from java to js.
Thank u all.


问:
iOS11 Core NFC and ISO 14443
As I understand the iOS11 Core NFC, it only supports NDEF. Does this mean that it only supports ISO 15693 tags and does not support ISO 14443 (-3 or -4)?

I know that you can send APDUs in NDEF but that's not ISO 7816. Please correct me if I am wrong. Simply, does CoreNFC support ISO 14443 (-3/-4)?

答:
No, Core NFC is not limited to ISO/IEC 15693 tags at all. According to the documentation (Core NFC),

Using Core NFC, you can read Near Field Communication (NFC) tags of
  types 1 through 5 that contain data in the NFC Data Exchange Format
  (NDEF).

So Core NFC seems to support only tags that are NDEF formatted. NDEF is the NFC Data Exchange Format, an abstraction layer specified by the NFC Forum to abstract interaction with and data storage on different types of NFC tag hardware. There are currently five different NFC tag platforms specified by the NFC Forum and supported by iOS. Each of these tag types originates from certain RFID (NFC) tag products that already existed before NFC was born. They differ in their commad sets, memory layout and even the underlying RF protocol standard:

NFC Forum Tag Type 1: This tag platform originates from Innovision (now Broadcom?) Jewel tags. It is based on ISO/IEC 14443-3A framing but does not use the anti-collision scheme from that standard.

NFC Forum Tag Type 2: This tag platform originates from NXP MIFARE Ultralight tags. It is based on ISO/IEC 14443-3A.

NFC Forum Tag Type 3: This tag platform originates from Sony FeliCa Lite tags. It is based on JIS X 6319-4 (and ISO/IEC 18092).

NFC Forum Tag Type 4: This tag platform originates from NXP MIFARE DESFire tags. It is based on ISO/IEC 14443-4 (ISO-DEP) transmission protocol (both Type A and Type B supported) and ISO/IEC 7816-4 commands (APDUs) and file system structures.

NFC Forum Tag Type 5: This tag platform was an agreement between features from ISO/IEC 15693 tags of different manufacturers.

Consequently, Core NFC supports subsets of all these NFC / RFID / contactless smartcard standards in the 13.56 MHz HF band. Nevertheless, you are bound to the features that are exposed though the NDEF abstraction layer. This means that you can only use those RF standards to read NDEF messages on supported NFC tags.

Also, while APDUs are used to access Type 4 tags, you are bound to those APDUs and those communication sequences that are used to read data from these tags. You can't freely control what APDUs are being sent.

Title: iOS11 Core NFC and ISO 14443


问:
how to show image from url in php codeigniter
```<code> In controller:
public function submit_image() {
    $post = $this->input->post ();
    $this->common->submit_image ( $_FILES, $post );
    $this->session->set_flashdata ( 'success', "alert came" );
    redirect ( BASE_URL . 'admin/media_mgmt/' );
}

In model:
function submit_image($file, $data) {
    if ($fname = is_valid_val ( $data, 'name', FALSE )) {
        $this->db->set ( 'name', $this->db->escape_str ( htmlspecialchars ( $fname ) ) );
    }
    if ($fname = is_valid_val ( $data, 'tag', FALSE )) {
        $this->db->set ( 'tag', $this->db->escape_str ( htmlspecialchars ( $fname ) ) );
    }
    $name = upload_media_image ( $file );

    if ($name) {
        $data1 ['media_img'] =  BASE_PATH . MEDIA_PHOTO . '/' . $name;
        $this->db->set ( 'image', $this->db->escape_str ( htmlspecialchars ( $data1 ['media_img'] ) ) );
    }

    if ($id = is_valid_val ( $data, 'id', FALSE )) {
        $this->db->where ( 'id', $this->db->escape_str ( htmlspecialchars ( $id ) ) );
        $this->db->update ( TBL_MEDIA_PHOTO );
        if ($this->db->affected_rows () > 0) {
            return 1;
        } else {
            return FALSE;
        }
    } else {
        $this->db->insert ( TBL_MEDIA_PHOTO );
        if ($id = $this->db->insert_id ()) {
            return 1;
        }
    }
}

In php:
var image_list = $('#demo-foo-filtering').DataTable( {

     "processing": true,
     "serverSide": true,
     "ajax": {
         "url": "<?php echo BASE_URL;?>admin/ajax_image_list",
         "type": "POST"
     },
     "columns": [
         { "data": "id" },
         { "data": "name" },
         { "data": "tag" },
         { "data": "image" },

     ],

 } );
 $('#image_form').parsley().on('form:success', function() {
     var formdata = $('#image_form').serialize();
            $.ajax({
                url:"<?php echo BASE_URL.'admin/submit_image';?>",
                type: 'POST',
                data: formdata,
                success: function(res) {
                        if(res==1){
                            Custombox.close();
                            $('#success_edit').css("display",'block');
                            $('#success_edit').fadeIn().delay(3000).fadeOut();
                        }else{
                            //$('#error_edit').css("display",'block');

                        }
                }
            })
     });
</code>```

This is my controller model and php code.I want to display only image in admin panel.now the image is coming as "http://localhost/edudux_web/manage/media_photo//4.jpg" when getting from database. instead of url i want to show actual image on panel

答:
```<code>  <!-- ============================================================== -->
<!-- Start right Content here -->
<!-- ============================================================== -->
         <div class="content-page">
<!-- Start content -->
       <div class="content">
    <div class="container">

        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">

                <h4 class="page-title">Gallery</h4>
                <ol class="breadcrumb">

                </ol>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 ">
                <div class="portfolioFilter">
                    <a href="#" data-filter="*" class="current"
            onclick="showall()">All</a>
                    <a href="#" data-filter=".webdesign"
              onclick="showimgbutton()">Images</a>
                    <a href="#" data-filter=".graphicdesign"
                        onclick="showvideobutton()">Videos</a>
                    <button id="imga"
                        class="btn btn-default btn-md waves-effect waves-
  light "
                        data-toggle="modal" data-target="#myModal"
                        style="visibility: hidden">
                        <i class="md md-add"></i> Add Image
                    </button>
                    <a id="imgv" href="#custom-modal1"
                        class="btn btn-default btn-md waves-effect waves-
                         light "
                        data-animation="fadein" data-plugin="custommodal"
                        data-overlaySpeed="200" data-overlayColor="#36404a"
                        style="visibility: hidden"> <i class="md md-add">
             </i> Add Video
                    </a>
                </div>
            </div>
        </div>
        <div role="alert"
            class="alert alert-success alert-dismissible fade in"
            id="success_edit" style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                    <span aria-hidden="true">x</span>
            </button>
            <strong>Hey!</strong> Image Added Successfully.
        </div>
        <div role="alert"
            class="alert alert-danger alert-dismissible fade in"
       id="error_edit"
            style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                <span aria-hidden="true">x</span>
            </button>
            <strong>Oops!</strong> Error while Image add.
        </div>
        <div role="alert"
            class="alert alert-success alert-dismissible fade in"
            id="success_edit1" style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                <span aria-hidden="true">x</span>
            </button>
            <strong>Hey!</strong> Video Added Successfully.
        </div>
        <div role="alert"
            class="alert alert-danger alert-dismissible fade in"
            id="error_edit1" style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                <span aria-hidden="true">x</span>
            </button>
            <strong>Oops!</strong> Error while Video add.
        </div>
        <script type="text/javascript">
            function showimgbutton()
            {
                $('#imga').css("visibility",'visible');
                $('#imgv').css("visibility",'hidden');
            }
            function showvideobutton()
            {
                $('#imga').css("visibility",'hidden');
                $('#imgv').css("visibility",'visible');
            }
            function showall()
            {
                $('#imga').css("visibility",'hidden');
                $('#imgv').css("visibility",'hidden');
            }
        </script>
        <table id="demo-foo-filtering"
            class="table table-striped dataTables_wrapper" data-page-
            size="7">
            <thead>
                <tr>
                    <th>ID</th>
                    <th data-toggle="true">Name</th>
                    <th>Tags</th>
                    <th data-hide="phone">Image</th>

                    <img src="<?php echo BASE_PATH; ?>media_photo/">

                </tr>
            </thead>
            <tfoot>
            </tfoot>
                </table>
                <!-- <div class="row port">
            <div class="portfolioContainer">
                <div class="col-sm-6 col-lg-3 col-md-4 webdesign
             illustrator">
                    <div class="gal-detail thumb"><!-- <img src="<?php echo
             $row['gallery_image'];?>" alt="">
                        <a
                            href="<?php echo BASE_PATH;?
        >admin_assets/images/gallery/1.jpg"
                            class="image-popup" title="Screenshot-1">
                                <img
                            src="<?php echo BASE_PATH;?
               >admin_assets/images/gallery/1.jpg"
                            class="thumb-img" alt="work-thumbnail">
                        </a>
                        <h4>School Image1</h4>
                    </div>
                </div>

                <div
                    class="col-sm-6 col-lg-3 col-md-4 webdesign illustrator
             photography">
                    <div class="gal-detail thumb">
                        <a
                            href="<?php echo BASE_PATH;?
         >admin_assets/images/gallery/2.jpg"
                            class="image-popup" title="Screenshot-2">
                            <img
                            src="<?php echo BASE_PATH;?
          >admin_assets/images/gallery/2.jpg"
                            class="thumb-img" alt="work-thumbnail">
                        </a>
                        <h4>School Image2</h4>
                    </div>
                </div>

                <div
                    class="col-sm-6 col-lg-3 col-md-4  webdesign illustrator
             photography">
                    <div class="gal-detail thumb">
                        <a href="<?php echo BASE_PATH;?
         >assets/images/gallery/3.jpg"
                            class="image-popup" title="Screenshot-3"> <img
                            src="<?php echo BASE_PATH;?
            >admin_assets/images/gallery/3.jpg"
                            class="thumb-img" alt="work-thumbnail">
                        </a>
                        <h4>School Image3</h4>
                    </div>
                </div>-->

        <div class="col-md-4   graphicdesign illustrator photography">
            <div class="card-box gal-detail thumb">
                <h4 class="text-dark header-title m-t-0">Video 1</h4>

                <!-- 16:9 aspect ratio-->

                <div class="embed-responsive embed-responsive-16by9">
                     <iframe height="100%" width="100%"
                    src="https://www.youtube.com/embed/">
                </iframe>
                </div>
            </div>
        </div>
        <div class="col-md-4   graphicdesign illustrator photography">
            <div class="card-box gal-detail thumb">
                <h4 class="text-dark header-title m-t-0">Video 2</h4>

                <!-- 16:9 aspect ratio-->

                <div class="embed-responsive embed-responsive-16by9">
            <!--         <iframe height="100%" width="100%"
                    src="https://www.youtube.com/embed/kwkkkuAf19g">
                </iframe>  -->
                </div>
            </div>
        </div>

    </div>
    </div>
    <!-- End row -->

       </div>
      <!-- container -->

           </div>
          <!-- content -->
              </div>
        <div id="myModal" class="modal fade" tabindex="-1" role="dialog"
      aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">
                <span>×</span><span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title" id="myModalLabel">Add Image</h4>
        </div>
        <div class="modal-body">
            <form id="image_form" class="form-horizontal" role="form"
                data-parsley-validate novalidate enctype="multipart/form-
           data"
                method="post" action="<?php echo
               BASE_URL.'admin/submit_image'?>">
                <div class="form-group">
                    <label for="userName" class="col-sm-4 control-
                   label">Name*</label>
                    <div class="col-sm-7">
                        <input type="text" name="name" data-parsley-
        trigger="change"
                            required placeholder="" class="form-control"
     id="name">
                    </div>
                </div>

                <div class="form-group">
                    <label for="userName" class="col-sm-4 control-
            label">Tag</label>
                    <div class="col-sm-8">
                        <input type="text" name="tag" size="8"
                 placeholder=""
                            class="form-control" id="tag" data-
           role="tagsinput">
                        <!-- <textarea class="form-control" rows="5" data-
               role="tagsinput"></textarea> -->
                    </div>
                </div>
                <div class="form-group">
                    <label for="userName" class="col-sm-4 control-
              label">Upload Image</label>
                    <div class="col-sm-7">
                        <input type="file" class="filestyle" required
                   name="media_img"
                            id="media_img" data-iconname="fa fa-cloud-
                 upload">

                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-8">
                        <button type="submit" id="submit_image"
                            class="btn btn-primary waves-effect waves-
               light">Submit</button>
                        <button type="reset"
              onclick="$('#myModal').modal('hide');"
                            class="btn btn-default waves-effect waves-light
               m-l-5">Cancel</button>
                    </div>
                </div>
            </form>
        </div>

    </div>
    <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
            </div>
                 <!-- Modal -->
        <div id="custom-modal1" class="modal-demo">
  <button type="button" class="close" onclick="Custombox.close();">
    <span>×</span><span class="sr-only">Close</span>
  </button>
  <h4 class="custom-modal-title">Add Video</h4>
  <div class="custom-modal-text text-left">
    <form id="video_form" class="form-horizontal" role="form"
        data-parsley-validate novalidate
        action="<?php echo BASE_URL.'admin/submit_video'?>">
        <div class="form-group">
            <label for="userName" class="col-sm-4 control-label">Name*
           </label>
            <div class="col-sm-7">
                <input type="text" name="name" data-parsley-trigger="change"
                    required placeholder="" class="form-control" id="name">
            </div>
        </div>

        <div class="form-group">
            <label for="userName" class="col-sm-4 control-label">Tag</label>
            <div class="col-sm-7">
                <input type="text" name="tag" data-parsley-trigger="change"
                    placeholder="" class="form-control" id="tag">
            </div>
        </div>
        <div class="form-group">
            <label for="userName" class="col-sm-4 control-label">Url</label>
            <div class="col-sm-7">
                <input type="url" required data-parsley-type="url"
                      name="url"
                    data-parsley-trigger="change" required placeholder=""
                    class="form-control" id="url">

            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-4 col-sm-8">
                <button type="button" id="submit_video"
                    class="btn btn-primary waves-effect waves-
         light">Submit</button>
                <button type="reset" onclick="Custombox.close();"
                    class="btn btn-default waves-effect waves-light m-l-
            5">Cancel</button>
            </div>
        </div>
    </form>
        </div>
        </div>
     <!-- ============================================================== -->
     <!-- End Right content here -->
   <!-- ============================================================== -->
     <script src="<?php echo BASE_PATH;?>assets/js/jquery-2.js"></script>
     <script type="text/javascript"
  src="<?php echo BASE_PATH;?>assets/js/jquery.validate.min.js"></script>
    <script
   src="<?php echo BASE_PATH;?>assets/parsleyjs/dist/parsley.min.js">
    </script>
      <script type="text/javascript">
       $(document).ready(function(){

    $('#submit_image').on('click', function() {
      $('#image_form').parsley().validate();
    });

        var image_list = $('#demo-foo-filtering').DataTable( {

     "processing": true,
     "serverSide": true,
     "ajax": {
         "url": "<?php echo BASE_URL;?>admin/ajax_image_list",
         "type": "POST"
     },
     "columns": [
         { "data": "id" },
         { "data": "name" },
         { "data": "tag" },
         { "data": "image" },

     ],

    } );
     $('#image_form').parsley().on('form:success', function() {
     var formdata = $('#image_form').serialize();
            $.ajax({
                url:"<?php echo BASE_URL.'admin/submit_image';?>",
                type: 'POST',
                data: formdata,
                success: function(res) {
                        if(res==1){
                            Custombox.close();
                            $('#success_edit').css("display",'block');

             $('#success_edit').fadeIn().delay(3000).fadeOut();
                        }else{
                            //$('#error_edit').css("display",'block');
                        }

                }
            })
     });

    $('#submit_video').on('click', function() {
     $('#video_form').parsley().validate();
     //validateFront();
   });
    $('#video_form').parsley().on('form:success', function() {
     var formdata = $('#video_form').serialize();
            $.ajax({
                url:"<?php echo BASE_URL.'admin/submit_video';?>",
                type: 'POST',
                data: formdata,
                success: function(res) {
                        if(res==1){
                            Custombox.close();
                            $('#success_edit1').css("display",'block');

             $('#success_edit1').fadeIn().delay(3000).fadeOut();
                        }else{
                            //$('#error_edit').css("display",'block');
                        }
                }
            })
     });
    $("#photo").change(function(){
        readURL(this);
    });
       });

 </script>
</code>```

Body:
 In controller:
public function submit_image() {
    $post = $this->input->post ();
    $this->common->submit_image ( $_FILES, $post );
    $this->session->set_flashdata ( 'success', "alert came" );
    redirect ( BASE_URL . 'admin/media_mgmt/' );
}

In model:
function submit_image($file, $data) {
    if ($fname = is_valid_val ( $data, 'name', FALSE )) {
        $this->db->set ( 'name', $this->db->escape_str ( htmlspecialchars ( $fname ) ) );
    }
    if ($fname = is_valid_val ( $data, 'tag', FALSE )) {
        $this->db->set ( 'tag', $this->db->escape_str ( htmlspecialchars ( $fname ) ) );
    }
    $name = upload_media_image ( $file );

    if ($name) {
        $data1 ['media_img'] =  BASE_PATH . MEDIA_PHOTO . '/' . $name;
        $this->db->set ( 'image', $this->db->escape_str ( htmlspecialchars ( $data1 ['media_img'] ) ) );
    }

    if ($id = is_valid_val ( $data, 'id', FALSE )) {
        $this->db->where ( 'id', $this->db->escape_str ( htmlspecialchars ( $id ) ) );
        $this->db->update ( TBL_MEDIA_PHOTO );
        if ($this->db->affected_rows () > 0) {
            return 1;
        } else {
            return FALSE;
        }
    } else {
        $this->db->insert ( TBL_MEDIA_PHOTO );
        if ($id = $this->db->insert_id ()) {
            return 1;
        }
    }
}

In php:
var image_list = $('#demo-foo-filtering').DataTable( {

     "processing": true,
     "serverSide": true,
     "ajax": {
         "url": "<?php echo BASE_URL;?>admin/ajax_image_list",
         "type": "POST"
     },
     "columns": [
         { "data": "id" },
         { "data": "name" },
         { "data": "tag" },
         { "data": "image" },

     ],

 } );
 $('#image_form').parsley().on('form:success', function() {
     var formdata = $('#image_form').serialize();
            $.ajax({
                url:"<?php echo BASE_URL.'admin/submit_image';?>",
                type: 'POST',
                data: formdata,
                success: function(res) {
                        if(res==1){
                            Custombox.close();
                            $('#success_edit').css("display",'block');
                            $('#success_edit').fadeIn().delay(3000).fadeOut();
                        }else{
                            //$('#error_edit').css("display",'block');

                        }
                }
            })
     });

This is my controller model and php code.I want to display only image in admin panel.now the image is coming as "http://localhost/edudux_web/manage/media_photo//4.jpg" when getting from database. instead of url i want to show actual image on panel

Body:
  <!-- ============================================================== -->
<!-- Start right Content here -->
<!-- ============================================================== -->
         <div class="content-page">
<!-- Start content -->
       <div class="content">
    <div class="container">

        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">

                <h4 class="page-title">Gallery</h4>
                <ol class="breadcrumb">

                </ol>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 ">
                <div class="portfolioFilter">
                    <a href="#" data-filter="*" class="current"
            onclick="showall()">All</a>
                    <a href="#" data-filter=".webdesign"
              onclick="showimgbutton()">Images</a>
                    <a href="#" data-filter=".graphicdesign"
                        onclick="showvideobutton()">Videos</a>
                    <button id="imga"
                        class="btn btn-default btn-md waves-effect waves-
  light "
                        data-toggle="modal" data-target="#myModal"
                        style="visibility: hidden">
                        <i class="md md-add"></i> Add Image
                    </button>
                    <a id="imgv" href="#custom-modal1"
                        class="btn btn-default btn-md waves-effect waves-
                         light "
                        data-animation="fadein" data-plugin="custommodal"
                        data-overlaySpeed="200" data-overlayColor="#36404a"
                        style="visibility: hidden"> <i class="md md-add">
             </i> Add Video
                    </a>
                </div>
            </div>
        </div>
        <div role="alert"
            class="alert alert-success alert-dismissible fade in"
            id="success_edit" style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                    <span aria-hidden="true">x</span>
            </button>
            <strong>Hey!</strong> Image Added Successfully.
        </div>
        <div role="alert"
            class="alert alert-danger alert-dismissible fade in"
       id="error_edit"
            style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                <span aria-hidden="true">x</span>
            </button>
            <strong>Oops!</strong> Error while Image add.
        </div>
        <div role="alert"
            class="alert alert-success alert-dismissible fade in"
            id="success_edit1" style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                <span aria-hidden="true">x</span>
            </button>
            <strong>Hey!</strong> Video Added Successfully.
        </div>
        <div role="alert"
            class="alert alert-danger alert-dismissible fade in"
            id="error_edit1" style="display: none;">
            <button aria-label="Close" data-dismiss="alert" class="close"
                type="button">
                <span aria-hidden="true">x</span>
            </button>
            <strong>Oops!</strong> Error while Video add.
        </div>
        <script type="text/javascript">
            function showimgbutton()
            {
                $('#imga').css("visibility",'visible');
                $('#imgv').css("visibility",'hidden');
            }
            function showvideobutton()
            {
                $('#imga').css("visibility",'hidden');
                $('#imgv').css("visibility",'visible');
            }
            function showall()
            {
                $('#imga').css("visibility",'hidden');
                $('#imgv').css("visibility",'hidden');
            }
        </script>
        <table id="demo-foo-filtering"
            class="table table-striped dataTables_wrapper" data-page-
            size="7">
            <thead>
                <tr>
                    <th>ID</th>
                    <th data-toggle="true">Name</th>
                    <th>Tags</th>
                    <th data-hide="phone">Image</th>

                    <img src="<?php echo BASE_PATH; ?>media_photo/">

                </tr>
            </thead>
            <tfoot>
            </tfoot>
                </table>
                <!-- <div class="row port">
            <div class="portfolioContainer">
                <div class="col-sm-6 col-lg-3 col-md-4 webdesign
             illustrator">
                    <div class="gal-detail thumb"><!-- <img src="<?php echo
             $row['gallery_image'];?>" alt="">
                        <a
                            href="<?php echo BASE_PATH;?
        >admin_assets/images/gallery/1.jpg"
                            class="image-popup" title="Screenshot-1">
                                <img
                            src="<?php echo BASE_PATH;?
               >admin_assets/images/gallery/1.jpg"
                            class="thumb-img" alt="work-thumbnail">
                        </a>
                        <h4>School Image1</h4>
                    </div>
                </div>

                <div
                    class="col-sm-6 col-lg-3 col-md-4 webdesign illustrator
             photography">
                    <div class="gal-detail thumb">
                        <a
                            href="<?php echo BASE_PATH;?
         >admin_assets/images/gallery/2.jpg"
                            class="image-popup" title="Screenshot-2">
                            <img
                            src="<?php echo BASE_PATH;?
          >admin_assets/images/gallery/2.jpg"
                            class="thumb-img" alt="work-thumbnail">
                        </a>
                        <h4>School Image2</h4>
                    </div>
                </div>

                <div
                    class="col-sm-6 col-lg-3 col-md-4  webdesign illustrator
             photography">
                    <div class="gal-detail thumb">
                        <a href="<?php echo BASE_PATH;?
         >assets/images/gallery/3.jpg"
                            class="image-popup" title="Screenshot-3"> <img
                            src="<?php echo BASE_PATH;?
            >admin_assets/images/gallery/3.jpg"
                            class="thumb-img" alt="work-thumbnail">
                        </a>
                        <h4>School Image3</h4>
                    </div>
                </div>-->

        <div class="col-md-4   graphicdesign illustrator photography">
            <div class="card-box gal-detail thumb">
                <h4 class="text-dark header-title m-t-0">Video 1</h4>

                <!-- 16:9 aspect ratio-->

                <div class="embed-responsive embed-responsive-16by9">
                     <iframe height="100%" width="100%"
                    src="https://www.youtube.com/embed/">
                </iframe>
                </div>
            </div>
        </div>
        <div class="col-md-4   graphicdesign illustrator photography">
            <div class="card-box gal-detail thumb">
                <h4 class="text-dark header-title m-t-0">Video 2</h4>

                <!-- 16:9 aspect ratio-->

                <div class="embed-responsive embed-responsive-16by9">
            <!--         <iframe height="100%" width="100%"
                    src="https://www.youtube.com/embed/kwkkkuAf19g">
                </iframe>  -->
                </div>
            </div>
        </div>

    </div>
    </div>
    <!-- End row -->

       </div>
      <!-- container -->

           </div>
          <!-- content -->
              </div>
        <div id="myModal" class="modal fade" tabindex="-1" role="dialog"
      aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"
                aria-hidden="true">
                <span>&times;</span><span class="sr-only">Close</span>
            </button>
            <h4 class="modal-title" id="myModalLabel">Add Image</h4>
        </div>
        <div class="modal-body">
            <form id="image_form" class="form-horizontal" role="form"
                data-parsley-validate novalidate enctype="multipart/form-
           data"
                method="post" action="<?php echo
               BASE_URL.'admin/submit_image'?>">
                <div class="form-group">
                    <label for="userName" class="col-sm-4 control-
                   label">Name*</label>
                    <div class="col-sm-7">
                        <input type="text" name="name" data-parsley-
        trigger="change"
                            required placeholder="" class="form-control"
     id="name">
                    </div>
                </div>

                <div class="form-group">
                    <label for="userName" class="col-sm-4 control-
            label">Tag</label>
                    <div class="col-sm-8">
                        <input type="text" name="tag" size="8"
                 placeholder=""
                            class="form-control" id="tag" data-
           role="tagsinput">
                        <!-- <textarea class="form-control" rows="5" data-
               role="tagsinput"></textarea> -->
                    </div>
                </div>
                <div class="form-group">
                    <label for="userName" class="col-sm-4 control-
              label">Upload Image</label>
                    <div class="col-sm-7">
                        <input type="file" class="filestyle" required
                   name="media_img"
                            id="media_img" data-iconname="fa fa-cloud-
                 upload">

                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-4 col-sm-8">
                        <button type="submit" id="submit_image"
                            class="btn btn-primary waves-effect waves-
               light">Submit</button>
                        <button type="reset"
              onclick="$('#myModal').modal('hide');"
                            class="btn btn-default waves-effect waves-light
               m-l-5">Cancel</button>
                    </div>
                </div>
            </form>
        </div>

    </div>
    <!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
            </div>
                 <!-- Modal -->
        <div id="custom-modal1" class="modal-demo">
  <button type="button" class="close" onclick="Custombox.close();">
    <span>&times;</span><span class="sr-only">Close</span>
  </button>
  <h4 class="custom-modal-title">Add Video</h4>
  <div class="custom-modal-text text-left">
    <form id="video_form" class="form-horizontal" role="form"
        data-parsley-validate novalidate
        action="<?php echo BASE_URL.'admin/submit_video'?>">
        <div class="form-group">
            <label for="userName" class="col-sm-4 control-label">Name*
           </label>
            <div class="col-sm-7">
                <input type="text" name="name" data-parsley-trigger="change"
                    required placeholder="" class="form-control" id="name">
            </div>
        </div>

        <div class="form-group">
            <label for="userName" class="col-sm-4 control-label">Tag</label>
            <div class="col-sm-7">
                <input type="text" name="tag" data-parsley-trigger="change"
                    placeholder="" class="form-control" id="tag">
            </div>
        </div>
        <div class="form-group">
            <label for="userName" class="col-sm-4 control-label">Url</label>
            <div class="col-sm-7">
                <input type="url" required data-parsley-type="url"
                      name="url"
                    data-parsley-trigger="change" required placeholder=""
                    class="form-control" id="url">

            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-4 col-sm-8">
                <button type="button" id="submit_video"
                    class="btn btn-primary waves-effect waves-
         light">Submit</button>
                <button type="reset" onclick="Custombox.close();"
                    class="btn btn-default waves-effect waves-light m-l-
            5">Cancel</button>
            </div>
        </div>
    </form>
        </div>
        </div>
     <!-- ============================================================== -->
     <!-- End Right content here -->
   <!-- ============================================================== -->
     <script src="<?php echo BASE_PATH;?>assets/js/jquery-2.js"></script>
     <script type="text/javascript"
  src="<?php echo BASE_PATH;?>assets/js/jquery.validate.min.js"></script>
    <script
   src="<?php echo BASE_PATH;?>assets/parsleyjs/dist/parsley.min.js">
    </script>
      <script type="text/javascript">
       $(document).ready(function(){

    $('#submit_image').on('click', function() {
      $('#image_form').parsley().validate();
    });

        var image_list = $('#demo-foo-filtering').DataTable( {

     "processing": true,
     "serverSide": true,
     "ajax": {
         "url": "<?php echo BASE_URL;?>admin/ajax_image_list",
         "type": "POST"
     },
     "columns": [
         { "data": "id" },
         { "data": "name" },
         { "data": "tag" },
         { "data": "image" },

     ],

    } );
     $('#image_form').parsley().on('form:success', function() {
     var formdata = $('#image_form').serialize();
            $.ajax({
                url:"<?php echo BASE_URL.'admin/submit_image';?>",
                type: 'POST',
                data: formdata,
                success: function(res) {
                        if(res==1){
                            Custombox.close();
                            $('#success_edit').css("display",'block');

             $('#success_edit').fadeIn().delay(3000).fadeOut();
                        }else{
                            //$('#error_edit').css("display",'block');
                        }

                }
            })
     });

    $('#submit_video').on('click', function() {
     $('#video_form').parsley().validate();
     //validateFront();
   });
    $('#video_form').parsley().on('form:success', function() {
     var formdata = $('#video_form').serialize();
            $.ajax({
                url:"<?php echo BASE_URL.'admin/submit_video';?>",
                type: 'POST',
                data: formdata,
                success: function(res) {
                        if(res==1){
                            Custombox.close();
                            $('#success_edit1').css("display",'block');

             $('#success_edit1').fadeIn().delay(3000).fadeOut();
                        }else{
                            //$('#error_edit').css("display",'block');
                        }
                }
            })
     });
    $("#photo").change(function(){
        readURL(this);
    });
       });

 </script>


问:
Expanding menu not responding
I'm trying to fix a mobile menu in a WordPress child theme (from Twentyseventeen) that is no longer expanding when 'menu' is clicked. Basically I've had to tear the header apart to move things around and now the aria expanded menu isn't recognised. Instead I'm trying to use javascript to change the display property of the ul from none to block, but this isn't working either - mostly because I don't know the first thing about js and I've just tried making something from bits and pieces of code.

The demo of the site is live at http://www.histeve.co.uk/testing/triangledrivertraining/

The javascript I'm trying to use is as follows:

```<code><script>
var element = document.getElementById("topMenu");
document.getElementById("navBtn").addEventListener("click", toggleNav);

function toggleNav() {
if( element.style.display == 'none' ) {
function show() {('#topMenu').css ('display:block');}
} else {
function hide() {('#topMenu').css ('display:none'); }}
}
</script>
</code>```

This is no longer kicking out errors, but it's not doing anything at all.

If anyone has any ideas, your help is greatly appreciated!

Thanks
Steve

答:
Try this:

```<code><script>
    var $topMenu = jQuery("#topMenu");
    jQuery("#navBtn").click(toggleNav);

    function toggleNav() {
        if($topMenu.is(":visible")) {
            $topMenu.hide();
        } else {
            $topMenu.show();
        }
    }
</script>
</code>```

UPDATE:

To always show the menu on desktop you should go with this solution:

Add following styles to your page:

```<code> <style>
    @media (max-width: 768px) {
        .menu-navigation-container {
            display: none;
        }
        .menu-navigation-container.show-on-mobile {
            display: block;
        }
    }
</style>
</code>```

Add use this JS:

```<code><script>
    var $topMenu = jQuery(".menu-navigation-container");
    jQuery("#navBtn").click(function(){
        $topMenu.toggleClass("show-on-mobile");
    });
</script>
</code>```

Title: Expanding menu not responding

Body:
I'm trying to fix a mobile menu in a WordPress child theme (from Twentyseventeen) that is no longer expanding when 'menu' is clicked. Basically I've had to tear the header apart to move things around and now the aria expanded menu isn't recognised. Instead I'm trying to use javascript to change the display property of the ul from none to block, but this isn't working either - mostly because I don't know the first thing about js and I've just tried making something from bits and pieces of code.

The demo of the site is live at http://www.histeve.co.uk/testing/triangledrivertraining/

The javascript I'm trying to use is as follows:

This is no longer kicking out errors, but it's not doing anything at all.

If anyone has any ideas, your help is greatly appreciated!

Thanks
Steve

Body:
Try this:

<script>
    var $topMenu = jQuery("#topMenu");
    jQuery("#navBtn").click(toggleNav);

    function toggleNav() {
        if($topMenu.is(":visible")) {
            $topMenu.hide();
        } else {
            $topMenu.show();
        }
    }
</script>

UPDATE:

To always show the menu on desktop you should go with this solution:

Add following styles to your page:

 <style>
    @media (max-width: 768px) {
        .menu-navigation-container {
            display: none;
        }
        .menu-navigation-container.show-on-mobile {
            display: block;
        }
    }
</style>

Add use this JS:

<script>
    var $topMenu = jQuery(".menu-navigation-container");
    jQuery("#navBtn").click(function(){
        $topMenu.toggleClass("show-on-mobile");
    });
</script>


问:
Find years where 22nd March will be a Tuesday
I need to find out in which years between 2017 and 2100 (both inclusive) will the 22nd March be a Tuesday.

I tried using the datetime module but I couldn't figure out how...

答:
You could use isoweekday from the datetime module:

```<code>import datetime

for year in range(2017, 2101):
    if datetime.date(year, 3, 22).isoweekday() == 2:  # 2 is Tuesday
        print(year)
</code>```

or weekday:

```<code>import datetime

for year in range(2017, 2101):
    if datetime.date(year, 3, 22).weekday() == 1:  # now 1 is Tuesday
        print(year)
</code>```

You can also use a comprehension to collect them in a list:

```<code>>>> [year for year in range(2017, 2101) if datetime.date(year, 3, 22).isoweekday() == 2]
[2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095]
</code>```

Body:
You could use isoweekday from the datetime module:

import datetime

for year in range(2017, 2101):
    if datetime.date(year, 3, 22).isoweekday() == 2:  # 2 is Tuesday
        print(year)

or weekday:

import datetime

for year in range(2017, 2101):
    if datetime.date(year, 3, 22).weekday() == 1:  # now 1 is Tuesday
        print(year)

You can also use a comprehension to collect them in a list:

>>> [year for year in range(2017, 2101) if datetime.date(year, 3, 22).isoweekday() == 2]
[2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095]


问:
Remove a page from Navigation Stack
I have this application schema :

```<code>[List Page] -> [Detail Page] -> [ShareOnFacebook Page]
                     ^__________________|
</code>```

The user select an Item in the [List Page]

The user may or may not click a Share button if he or she does, the application navigates to a [ShareOneFacebook page] which displays a Facebook Login Form, posts a message and navigates back

The user navigates back.

If the user shared on facebook, it will "repost" the message, because the application store the session so it will navigate back to ShareOnFacebook, and then back to my Detail page.

If the user didn't share, he goes back to the List Page.

How can I "ommit" the ShareOnFacebook page in my navigation stack ?

答:
I posted an example for the same issue here.

The Nonlinear Navigation Service Matt linked to essentially does the same thing but would probably be better than my simple example.

Title: Remove a page from Navigation Stack

Body:
I have this application schema :

[List Page] -> [Detail Page] -> [ShareOnFacebook Page]
                     ^__________________|

The user select an Item in the [List Page]

The user may or may not click a Share button if he or she does, the application navigates to a [ShareOneFacebook page] which displays a Facebook Login Form, posts a message and navigates back

The user navigates back.

If the user shared on facebook, it will "repost" the message, because the application store the session so it will navigate back to ShareOnFacebook, and then back to my Detail page.

If the user didn't share, he goes back to the List Page.

How can I "ommit" the ShareOnFacebook page in my navigation stack ?