w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Creating a pull down menu with folders in NUKE python
The nuke.Panel enumeration pulldown cannot handle strings in the values. You would have to replace any spaces with another character(s) and then create the pulldown. p = nuke.Panel('my custom panel') paths = [i.replace(" ", "-_-") for i in os.walk('E:').next()[1]] p.addEnumerationPulldown('my choices', paths) ret = p.show() Ultimately, it's probably better to use a PythonPanel instead if it can fit your needs. It can handle spaces in an Enumeration_Knob attached to the panel. import os import nuke import nukescripts p = nukescripts.PythonPanel("foo") k = nuke.Enumeration_Knob("bar", 'bar', os.walk('E:').next()[1]) p.addKnob(k) p.show()

Categories : Python

Python thread timer, not executing or executing instantly
You lost all the indentation in your code snippet, so it's hard to be sure what you did. The most obvious problem is responseTimer.start. That merely retrieves the start method of your responseTimer object. You need to call that method to start the timer; i.e., do responseTimer.start(). Then it will produce the output you expected, with a delay of about 2 seconds before the final "timeout!" is printed.

Categories : Python

Dot Net Nuke Ajax Response Returning HTML
DNN's service layer allows you to follow a Webapi like approach, I think you'll find that easier for controlling the data to/from. Here's an example of a controller for an open source articles module https://dnnsimplearticle.codeplex.com/SourceControl/latest#cs/services/DnnSimpleArticleController.cs Something like public HttpResponseMessage GetAllArticles(int portalId, bool sortAsc) { try { //todo: get the latest X articles? var articles = ArticleController.GetAllArticles(portalId, sortAsc); //because of the circular reference when cerealizing the taxonomy within content items we have to build out our article view models manually. var cleanArticles = new List<ArticleViewModel>();

Categories : Ajax

what is the executing sequence of "switch case" in node js
The fs.readFile method is asynchronous. When you call it, execution continues immediately after it (at the break statement), and then proceeds to the console.log(5), and the response.end() calls. Therefore, response.end() is being called before the fs.readFile callback gets a chance to execute. You need to move the response.end() call inside the callback.

Categories : Javascript

How to prevent malicious *.js scripts from executing in Node.js
Most (all?) modules have source code available on Github, you can read through the source and look for security problems, or hire a security professional to do the job. I just take the risk - although I tend to use popular packages with hundreds of commits, active maintenence, and issue lists.

Categories : Node Js

Cancel capitalization in python
Here's an idea: convert the input into lowercase before making any comparisons: tokens = test.lower().split() And make sure that all the elements in words are in lowercase, too: words = { e.lower() for e in words } By doing the above, we're comparing only lowercase characters throughout the program, so capitalization should not be a problem.

Categories : Python

Using node.js & async.js: series executing in the wrong order?
Perhaps try something like this: async.series([ function(callback) { routes.avg(req.query.url, resultObject); console.log('1'); callback(); }, function(callback) { console.log('2'); callback(); } ], function(err, results){ if(!err) res.send(resultObject); else //do something here for error? });

Categories : Node Js

working in python console while executing a boost::python module
You have two options: start python with the -i flag, that will cause to drop it to the interactive interperter instead of exiting from the main thread start an interactive session manually: import code code.interact() The second option is particularily useful if you want to run the interactive session in it's own thread, as some libraries (like PyQt/PySide) don't like it when they arn't started from the main thread: from code import interact from threading import Thread Thread(target=interact, kwargs={'local': globals()}).start() ... # start some mainloop which will block the main thread Passing local=globals() to interact is necessary so that you have access to the scope of the module, otherwise the interpreter session would only have access to the content of the thread's scope.

Categories : Python

Starting node.js with full config from gruntjs (before executing mocha tests)
We configure our app.js to start on a different port when being run from tests, so that we can keep the dev server running (using nodemon) on their regular ports at the same time. Here's our code: // Start server. if (process.env.TEST == 'true') { var port = process.env.PORT || 3500; // Used by Heroku and http on localhost process.env['PORT'] = process.env.PORT || 4500; // Used by https on localhost } else { var port = process.env.PORT || 3000; // Used by Heroku and http on localhost process.env['PORT'] = process.env.PORT || 4000; // Used by https on localhost } http.createServer(app).listen(port, function () { console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env); }); // Run separate https server if not on heroku if (p

Categories : Node Js

how to get the index of a child node under a parent node using python?
Using xml.etree.ElementTree: import xml.etree.ElementTree as ET root = ET.fromstring('''<?xml version="1.0"?> <BCPFORMAT ... </BCPFORMAT>''') # Accessing parent node: http://effbot.org/zone/element.htm#accessing-parents parent_map = {c: p for p in root.getiterator() for c in p} child = root.find('.//*[@ID="1"]') print(list(parent_map[child]).index(child)) # => 0 Using lxml: import lxml.etree as ET root = ET.fromstring('''<?xml version="1.0"?> <BCPFORMAT ... </BCPFORMAT>''') child = root.find('.//*[@ID="1"]') print(child.getparent().index(child)) # => 0

Categories : Python

How to check if a node exist before another node in an XML file using python
This can be done using XPath not(empty(//book[@id="bk108"][following-sibling::book[@id="bk112"]])) This XPath returns true if there is a book node with the id bk108 which does have a following book node with the id bk112

Categories : Python

after"" node exampleScript.js "" ,cant write in cmd
because your app is running and waiting any interaction to log your data. if you want to exit the app : ctrl+c if you want to run the app and be able to write in cmd : open another cmd :) run node using a compiler like netbeans or eclipse or even sublime-text

Categories : Javascript

How to cancel an event without using e.Cancel method?
You can't. WinForms events are just multicast delegates then they can't be canceled (in the sense of stop propagation of the event) unless this situation is handled by the object that exposes the event (but I'm now aware of any object that supports this, usually events are notifications). That said, some events has argument with a Cancel property, it's used by the object to cancel the action that should be performed because of that event. Again if the implementation does not provide that property there is not anything you can do to change this behavior. In your case you should override the OnCellClick method of DataGridView to handle that in the way you prefer (if you do not call the base class then cell won't get the click event and CellClick event won't be fired).

Categories : C#

Cannot cancel a task via CancellationTokenSource.Cancel()
I think you're probably expecting too much of CancellationToken. As regards Tasks, I think the CancellationToken is only used when determining whether to start the task when a slot is available for the task. Once the task is started, the task framework cannot simply abort the delegate call when the CancellationToken is cancelled. In order to fully cancel something like this, the code that is called by the Task framework (DoPosting) must be written to be aware of the CancellationToken and must check the state of that token directly at appropriate points in the code.

Categories : C#

IE10 issue executing function after document open but before document write?
You mention you're writing to an IFRAME. You can call this from IFRAME parent <iframe id="ifr"></iframe> <script type="text/javascript"> document.getElementById("ifr").contentWindow.document.open(); alert("Opened document"); document.getElementById("ifr").contentWindow.document.write("Hello World"); alert("Wrote to document"); document.getElementById("ifr").contentWindow.document.close(); alert("Closed document"); </script> Seems to work in IE as well.

Categories : Javascript

What is the best practice to write own node.js callbacks?
You should design all node callbacks according to the convention: var callback = function(err, data1, data2){ } The first argument to a callback should always be any error that might have occurred. You should follow this convention regardless of whether it's a callback for a node standard library or your own code. If you follow this convention then you'll be able to use libraries such as async.js or other promises libraries that rely on this convention. Domains rely on this convention as well.

Categories : Node Js

node.js serialport, trying to write and I just can't figure it out
I tested this on a console, not over a serial port, but I think it should work for you. There are two options: 1) you can escape into Unicode or 2) you can use the String.fromCharCode function (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) Escaping into Unicode is pretty simple, just use uXXXX where XXXX is the hex representation of your number sp.write('u0080123456 '); Or you can use String.fromCharCode: sp.write(String.fromCharCode(128) + '123456 ');

Categories : Node Js

node.js - how to write an array to file
A simple solution is to use writeFile : require("fs").writeFile( somepath, arr.map(function(v){ return v.join(', ')).join(' '), function (err) { console.log(err ? 'Error :'+err : 'ok' } );

Categories : Javascript

Node.js: PDFkit write to response
Assuming res is your server response object, just do this: doc.output(function(string) { res.end(string); }); This will send a string representation of the PDF rather than writing it to file. The code above is the compiled CoffeeScript that was in the documentation for PDFKit. doc.output (string) -> console.log string

Categories : Javascript

In node.js why i'm not getting error while trying to write the non existing file
Because the writeFile function creates the file if it does not exist. Basically, you can change the behavior of this function by submitting an options object as third parameter, as described in the documentation. For the flags property you can provide any value from the ones described in the documentation for fs.open. For write, they are: w - Open file for writing. The file is created (if it does not exist) or truncated (if it exists). wx - Like w but opens the file in exclusive mode. w+ - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). wx+ - Like w+ but opens the file in exclusive mode. The default value for writeFile is w, hence the file is created if it does not exist. As there is no option that provides an error when the

Categories : Node Js

How to write to response from HTTP Client Node.JS
What you are trying to do, is to make Request > Response server. But you are using Request module, that allows to get stuff rather than respond. What you need is http or better get express.js and use it, as it is straight forward and well popular web framework for exactly what you need.

Categories : Node Js

Is this the correct way to write asynchronous code in node.js?
This looks pretty solid. I would make a couple tweaks, the biggest being, it is conventional for callbacks to have function signature function callback(err, result1, result2..). And you call callback(null, content) if it worked, and callback('Problem') or callback(new Error('Problem')) if it didn't. I added error handling using the above convention. AFAIK lack of trailing semicolons doesn't break anything, but I added them out of force of habit. I moved the anonymous function that handles requests into its own function to make it clearer. And finally I reindented to 2 spaces because it makes callback hell much more manageable. var http = require('http'); var https = require('https'); var url = require('url'); var backendOptions = { port: 1414, hostname: 'data.backend.com', path: '

Categories : Javascript

Node.js - how to write scaffold generator for Express
If you want MVC framework in node js with generator functionalities then my prefer CompoundJS also routes and syntax are more similar to ruby on rails You can also do CRUD through it by compound generate crud post title content for controller compound g controller controllername actionName anotherActionName for Model compound g model user name password createdAt:date activated:boolean For Scaffold compound g scaffold post title content createdAt:date Thanks

Categories : Ruby On Rails

Write in a text file without overwriting in fs node js
Check the flags here: http://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback - you are currently using w+ which: 'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). You should use a instead: 'a' - Open file for appending. The file is created if it does not exist. 'ax' - Like 'a' but opens the file in exclusive mode. 'a+' - Open file for reading and appending. The file is created if it does not exist. 'ax+' - Like 'a+' but opens the file in exclusive mode.

Categories : Javascript

Node.js - res.end and res.write can accept a callback function
This appears to be a 'feature'. It is actually meant to be the encoding to be used in the body but the way the net module works is the second argument is an optional callback. The stack is like this (about) res.write(data, encoding) res._send(data, encoding) res._writeRaw(data, encoding) res.socket.write(data, encoding, cb) At that last point the number of arguments changes from 2 to 3. data and encoding to data, encoding, optional callback. So what is happening is your function (as the encoding argument) is being passed to socket.write where encoding can be optional. This could be considered a bug as you cannot push all three arguments from the response write method. I'd advise using it with extreme care.

Categories : Node Js

Simple way to write sync functions in node.js
You can use node-sync for that purpose https://github.com/0ctave/node-sync But in general I'd recommend you don't. The mocha test framework for example allows you to do async tests. Also async waterfall https://github.com/caolan/async#waterfall is a nice way to pseudo synchronize your code. I'd say stay in the async mind frame. Even when testing.

Categories : Javascript

executing perl script from python
Your Perl script is wrong: You read the path from STDIN, not from the command line arguments. You do not remove the newline after reading a line. You would be looking for "foo " instead of "foo". You have no error checking whatsoever. You do not load the Data::Dumper module. And are you sure that you really want to execute the file at $path as Perl code? Cleaned up, I'd write the Perl script as perl -MData::Dumper -do $ARGV[0];' -e'print Dumper \%some_global' input-file.pl >output Or as use strict; use warnings; use Data::Dumper do $ARGV[0]; open my $fh, ">", "output" or die "Can't open output: $!"; print { $fh } Dumper \%some_global; If you really want the filename from STDIN: use strict; use warnings; use Data::Dumper; chomp(my $path = <STDIN>); do $p

Categories : Python

Executing shell command from python
You can call a subprocess as if you were in the shell by using Popen() with the argument shell=True: subprocess.Popen("nohup ./op.o > myout.txt &", shell=True)

Categories : Python

Executing a python file from PHP - Linux
This is most likely a permission issue. Try echo exec("whoami"); This will let you know who php is running as. Then you need to verify this user can run the python script. If the file was not created by the same daemon that runs python, you will most likely be denied permission. Update This will let you know who owns all the files you are working with. The file being written to needs to be writable by the user that is running python. If you are running python from ssh, that is most likely not the same user as when you run python from exec. echo exec('whoami') . "<br>"; echo exec("ls -l test.txt") . "<br>"; echo exec("ls -l somefile.py") . "<br>"; Update 2 Because I constantly forget this exists. passthru('python somefile.py 1 2>&1'); This will e

Categories : PHP

Executing a set of codes when python GUI is clicked
Use the command option of a Button: from Tkinter import Tk, Button root = Tk() def func(): '''Place code to convert files in here''' print "Button has been pushed" Button(text="Push me", command=func).grid() root.mainloop() func will only run when the button is pressed.

Categories : Python

Executing an Excel macro from Python
I've never done this with EnsureDispatch, but here's how you do it with Dispatch from win32com.client import Dispatch xlApp = Dispatch('Excel.Application') result = xlApp.Run("<macro name here>",<the macro variables go here -seperate each one with a comma>) # for example: #result = xlApp.Run("myMacro", "foo","bar") #and make sure you close the xl xlApp.Quit() oh and I'm aslo on python 2.7, (but I doubt it will matter as the dependency is win32)

Categories : Python

Python script executing SQL on Synology NAS
you can install a mysql connector from official mysql source : http://dev.mysql.com/doc/connector-python/en/index.html. bye

Categories : Python

Convert html file in node.js to pdf and write the same in disk
Go through this link.. Here u can convert HTML file to PDF or HTML content to PDF import NDHTMLtoPDF.h and NDHTMLtoPDF.m from above source link pass HTML file path to generate PDF here.. NSURL *targetURL = [NSURL fileURLWithPath:HTMLPath]; Converting HTML to PDF self.PDFCreator = [NDHTMLtoPDF createPDFWithURL:targetURL pathForPDF:[[NSString stringWithFormat:@"~/Documents/Sample.pdf"] stringByExpandingTildeInPath] delegate:self pageSize:kPaperSizeA4 margins:UIEdgeInsetsMake(20, 5, 90, 5)]; pass HTML Content to generate PDF here.. NSString *str_PDFName_path = [NSString stringWithFormat:@"~/Documents/Sample.pdf"]; self.PDFCreator

Categories : Node Js

node.js write directly to the socket underlying http
When a request comes in, you should be able to access the connection property of the request. var http = require('http'); http.createServer(function (req, res) { req.connection.write(/* your data here */); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/'); Note that if you do this, you are also responsible for closing the connection when done. You could also just pipe the two streams together.

Categories : Node Js

Can't seem to get Node.js Command Line to interpret what I write, keeps returning "..."?
I use Node on *nix, so I'm not sure if it's different in Windows. But on *nix systems, the ellipses means it's waiting on you to finish a code block or the like. You should be able to hit CTRL+C (again, might be different in Windows) to cancel out of the edit you're in or CTRL+Z to kill the REPL entirely.

Categories : Windows

node.js write mongoDB collection to file using Streams?
You can use mongodump or mongoexport in order to create dumps of mongodb. mongodump is better for backing up and stores not just data, but a lot of meta data about the collections, like indexes. As well you can call it to specific database (-d) as well as collection (-c). To do it from node.js, use child_process.

Categories : Node Js

Python - When executing program via CMD, it just closes after the second input
This has to do with how Windows handles the execution. The default is to close right away after the program has terminated. There may be a setting to fix this, but a quick solution is to open up Command Prompt, cd to the direction, and execute your script directly.

Categories : Python

Executing Tkinter Code Successfully (Python 2.7)
It appears that you have some indentation issues. Python isn't free form, so you need to pay attention to indentation: from Tkinter import * class App(Frame): def __init__(self, master): Frame.__init__(self, master) self.grid() self.create_widgets() def create_widgets(self): self.entryLabel = Label(self, text="Please enter a list of numbers (no commas):") self.entryLabel.grid(row=0, column=0, columnspan=2) self.listEntry = Entry(self) self.listEntry.grid(row=0, column=2, sticky=E) self.entryLabel = Label(self, text="Please enter an index value:") self.entryLabel.grid(row=1, column=0, columnspan=2, sticky=E) self.indexEntry = Entry(self) self.indexEntry.grid(row=1, column=2) self.

Categories : Python

import module without executing whole script python
If the problem is arising from executing the LogInPage during the import... you can protect the code in LogInPage. Keep those codes in if __name__ == '__main__: block from being executed by import statements.

Categories : Python

Python Print Output Executing Out of Order
You're not closing the file when you do this: file.close You're just referencing the close method as a value. What you wanted was to call the close method: file.close() Eventually, the file gets garbage-collected, at which point all of its buffered data gets flushed. But meanwhile, you've opened the same file elsewhere and appended new data to it. On many platforms, your left-over buffers would end up overwriting the later-appended data, instead of getting added after them, making this even harder to debug. You got lucky here. :) If you ran this code through a linter, it would have warned you. With pylint, I get "W0104: Statement seems to have no effect". However, note that it can't possibly catch all such errors. For example: import random r = random.random Here, you're setti

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.