w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Python: Why does this code execute?
This is the output I get: 1 2 2 1 3 0 4 -1 5 -2 6 -3 7 -4 8 -5 9 -6 10 -7 Your question as to why it runs. Your outer most conditional is a while loop, which is true upon the first execution, however it runs right into a nested for loop. When this happens the while, will not be checked until the for loop finishes its first execution (which is why p = -7). What you want is this: p = 2 for i in range(10): if p <= 0: break print i+1 , p p-=1 which gives output: 1 2 2 1

Categories : Python

How to execute awk command by python code
While I agree that this is actually best done in Python, rather than invoking awk. If you really need to do this, then the actual error is with your awk. #!/usr/bin/env python import subprocess as sp args = ["awk", r'{OFS=" "; print $2,$4,$5,$6}', "B3LYPD.txt"] p = sp.Popen(args, stdin = sp.PIPE, stdout = sp.PIPE, stderr = sp.PIPE ) print(p.readline()) # will give you the first line of the awk output Edit: Fixed missing quote.

Categories : Python

How to execute code when a Python script is closed out?
import MySQLdb con = MySQLdb.connect(...) cursor = con.cursor() try: # do stuff with your DB finally: con.close() The finally clause is executed on success as well as on error (exception). If you hit Ctrl-C, you get a KeyboardInterrupt exception.

Categories : Python

Python execute code only if for loop did not begin iteration (with generator)?
I can't think of a better way than updating a boolean inside the for loop. any_results = False for x in g: any_results = True print x if not any_results: print 'Done'

Categories : Python

How to execute code on TFS server after a user checks in code
There are different ways you can approach this: Team Build. By using a TFS Build Server you can create a Continuous Integration build or a Gated Checkin build. In the build workflow you can then respond to whatever changes you've detected. You can use the TFS Client Object Model to grab the Changeset object. That contains all the data you'll need. The ALM Rangers have written an extensive guide explaining how to extend and customize the build process to suit your needs. Checkin Policy. By creating a custom checkin policy you can run code pre-checkin on the client (inside Visual Studio). This policy could serve as a sample on how to interact with the pending changes. ISubscriber TFS Application Tier plugin. Already mentioned by @ppejovic. The Application Tier plugin is installed on the TF

Categories : C#

Code to search in SQL for a value and if present execute a code
public List<UserData> GetData(int clientNo) { var theResults = new List<UserData>(); var connStr = "serverstring"; using (var cnn = new SqlConnection(connStr)) { cnn.Open(); using (var cmd = new SqlCommand("SELECT [Name], [PaternalLastName], [MaternalLastName] FROM [SocioInfo] Where ([SocioNum] = @SocioNum)",cnn)) { cmd.Parameters.AddWithValue("@SocioNum", txtInput.Text); using (var rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { while (rdr.Read()) { theResults.Add(new UserData {

Categories : C#

Code first: Database only created after execute certain code?
Database initialization is triggered lazily by Entity Framework. It will only occur when EF tries to connect to the database. You can manually trigger database initialization using the following. using (var db = new Models.TnHContext()) { db.Database.Initialize(force: false); } Setting the force parameter to false tells EF not to run initialization if it has already been triggered.

Categories : Dotnet

Execute a part of JS code after code above it
One Solution that just struck my mind is to use Callback functions. Wrap game code in a function like this: function callMeLater() { var activeFrame = 4, gameArray = []; for (var i = 0; i < 9; i++) { gameArray.push(['-','-','-','-','-','-','-','-','-']); } console.log(mode); // <<----- THIS HERE <<--------- if ( mode === 1 ) { $('body').on('click', 'div.frame', function() { var index = $frame.index(this); if ( index === activeFrame ) console.log('click on active Frame'); }); } else if ( mode === 2 ) { } } and call it from .animate() $notifier.css('display', 'table').animate({'opacity': 1}, 500, callMeLater); But this seems a bit weird to me. Any other choice that I have?

Categories : Javascript

How can I easily convert FORTRAN code to Python code (real code, not wrappers)
edit: added information on numpy Such a tool exists for Fortran to Lisp, or Fortran to C, or even Fortran to Java. But you will never have a Fortran to Python tool, for a simple reason: unlike Fortran, Lisp or C, Python does not have GOTO [1]. And there are many GOTOs in Fortran (especially Fortran IV) code. Even if there is a theorem by Jacopini stating that you can emulate GOTO with structured programming, it's far too cumbersome to implement a real (and efficient) language conversion tool. So not only will you need to translate the code of 1000 routines, but you will also need to understand each algorithm, with all its imbricated gotos, and translate the algorithm into a structured program before writing it in Python. Good luck! Hey, why do you think a wrapper is bad? Windows, OSX an

Categories : Python

Why won't this tic-tac-toe code execute?
Well there're many things which need improvement in your code (you have to rewrite your CheckAll function at least so it could check board of any size), but two things will help you to debug - first, you have to actually return something from your CheckAll function: ... if board[0] == board[1] == board[2]: return True if board[3] == board[4] == board[5]: return True ... second, you may actually want to print output: if checkAll() == True: print "The game is over!" break;

Categories : Python

Is it possible to execute code using a URL?
It's possible if something on the server takes the data in the URL and puts it somewhere where it might be treated as code (e.g. in an eval statement, in an SQL query or in an HTML document). The defences are all specific to the place where you put the data, but usually involve escaping it. See also SQL Injection, XSS, and the open web application security project.

Categories : PHP

Execute code before and after specification
Okay, as mentioned in my comment, I actually had this same issue. I needed to test Unfiltered endpoints, and the best way for each spec was to startup an Unfiltered server with a single endpoint, run the spec and then shutdown the server. To accomplish that, I first defined a base specification similar to this: import org.specs2.mutable.Specification abstract class SpecificationBase extends Specification{ //Do setup work here step{ println("Doing setup work...") success } //Include the real spec from the derived class include(spec) //Do shutdown work here step{ println("Doing shutdown work...") success } /** * To be implemented in the derived class. Returns the real specification * @return Specification */ def spec:Specification } Ba

Categories : Scala

Execute a program in my C code
To achieve what you want to do, you need to use popen(), not system(). Popen starts a new process that executes the program you specify in the command, and then maps the input or output stream of that program to a file descriptor available in your own program. Then, you can communicate with this program through this file descriptor. You code should look like (not actually compiled): FILE* file = popen("/path/to/your/program", "w") if (!file) { // Something not nice happened } fprintf(file, "command1 "); //... pclose(file);

Categories : C

java set of code does not execute
The following condition is invalid: if(myArray[i].contains("(") && myArray[i].contains(")") ) The same place in the array cannot hold both "(" and ")" - this condition will always return false! the array SUB is never initialized. Remark: for(i=0;!(line=reader.readLine()).isEmpty() && i<20;i++) will stop on the first empty line in the file, but sometimes there are empty lines and you still want to keep reading, if that is the case you should use != null instead if ! isEmpty()

Categories : Java

Using AJAX to execute PHP code
take a look to: http://api.jquery.com/load/ you can load only on part of a page in a html element $('#result').load('ajax/test.html #container');

Categories : PHP

Make PHP code execute only once
The usual approach: URL to create a new entry would be http://your.site/requests/new or http://your.site/requests/create or just http://your.site/request. URL to update an existing entry would be http://your.site/requests/123. After a new entry is created, the user is redirected to the /123 page where they can update their entry. The php is the same for both URLs. Check that isset($_GET['ID']) in which case, you are editing an existing record. If $_GET['ID'] is not set, then you are creating a new record. Wrap the INSERT statement in an if (isset($_GET['ID'])) block.

Categories : PHP

How do I execute a module's code from another?
Move the if __name__ == '__main__': in module a to the end of the file and add pass or some test code. Your problems are that: Any thing in the scope of if __name__ == '__main__': is only considered in the top level file. You are defining a class but not creating a class instance. module a, to be imported import statements class a1: def __init__(self, stuff): do stuff def run_proc(): #do stuff involving 'a1' when called from another module if __name__ == '__main__': pass # Replace with test code! Module that I'll run, that imports and uses 'a': import a def do_a(): A = a.a1() # Create an instance A.run_proc() # Use it if __name__ == '__main__': do_a()

Categories : Python

How does the PHP code execute even without closing the ?> PHP tag?
The closing tag exists to tell the interpretter that it should stop executing the text and just output it verbatim. Unlike XML, which requires openning and closing tags to match to be valid, the PHP interpretter simply uses the tags to delimit where execution should start and stop. Just like a PHP file could have no opening tag - meaining that the entire contents would be output, no closing tag is necessary as once the end-of-file is reached execution ends.

Categories : PHP

Why does it matter how I execute this code?
I'm sure you're right that it's to do with the delay between declaring the synthdef and it being ready. I'm not really experienced enough with sclang to immediately tell you exactly how you should change your code (I generally use scsynth via OSC, only using sclang to write SynthDefs), but you should be able to do something with the optional completionMsg argument to SynthDef.add.

Categories : Misc

Execute PHP code in DOMDocument
You ca use php eval() function to execute php inside the text. But i am not sure this is a safe way of doing it. You can see the PHP manual here: http://php.net/manual/en/function.eval.php

Categories : PHP

How to execute some code after a segue is done?
In case you don't want to use the viewDidAppear: method, you could create a custom segue. In the perform method you would use an animation for the transition, and that can have a completion block. You can add the code there after the animation is complete.

Categories : IOS

Use button to execute code and stop when done
You can use BackgroundWorker for it. See: http://msdn.microsoft.com/ru-ru/library/system.componentmodel.backgroundworker.aspx

Categories : C#

Javascript code seems to execute many times, why?
You're adding your event handlers for your popup in the button's onclick handler. That means they'll be added every time you click the button. In other words, the second time you open the popup by clicking the button, you have two click handlers on #insert-acf-form. The third time you'll have three, etc. The same goes for all the other event handlers you assign - but only the click handler will be immediately apparent, because mceInsertContent will be called twice. One solution: Since it appears that the popup is already created before you click the button the first time, you can add all the event handlers for it outside the onclick event handler - i.e., in your initialization code (note, code is only to demonstrate the idea, it is not tested and may include syntax errors and whatnot):

Categories : Javascript

Execute PHP code in a String without Eval
You don't need to execute PHP Code. You replace your {{ $user }} with PHP code, which doesn't get executed anymore. So your HTML will look like this after the replace: <?php echo "Dave" ?> Your Browser thinks <?...> is an HTML-tag and thus doesn't display the correct name. Solution: Just replace {{ $user }} with Dave, why do you want to add more PHP Code?

Categories : PHP

Execute line of code after returning value
Instead of this <some stuff>; yield return <something>; <some epilog stuff that should be executed after yield> do this: try { <some stuff>; yield return <something>; } finally { <some epilog stuff that should be executed after yield> }

Categories : C#

mPDF - Execute PHP code and save it as pdf
I used wkhtmltopdf for such things. which is an application not a library. http://code.google.com/p/wkhtmltopdf/ But i dont see what makes the difference between php and standard html . you can allways file_get_contents('http://server.com/script.php'); Then you can save this data as a html and do as you please with it.

Categories : PHP

execute code on scrolling down an element
$("#scroller").on('scroll', function() { var st = $(this).scrollTop(); $( 'li.frame1 img' ).css({ 'top' : -(st/3)+"px", 'left' : -(st/3)+"px" }); }); Replacing document with "#scroller" should do the job.

Categories : Jquery

IE doesn't execute my code 'onunload'
It's seems IE have bug where the unload event wouldn't fire on a specific page on a site. the unload event never fired since all the contents of the page hadn't finished loading before it's navigated to another page. try stopping it before you unload try this: function fixUnload() { // Is there things still loading, then fake the unload event if (document.readyState == 'interactive') { function stop() { // Prevent memory leak document.detachEvent('onstop', stop); // Call unload handler unload(); }; // Fire unload when the currently loading page is stopped document.attachEvent('onstop', stop); // Remove onstop listener after a while to prevent the unload function // to execute if

Categories : Javascript

Execute code repeatedly during animation?
You should look into using step or progress of the animate method: $('body').animate({ scrollTop: 0 }, { duration: 'slow', step: function(now, fx) { lastScrollTop = now; //Get the current scroll amount. }, complete: function() { lastScrollTop = $(this).scrollTop(); } }); now: the numeric value of the property being animated at each step fx: a reference to the jQuery.fx prototype object, which contains a number of properties such as elem for the animated element, start and end for the first and last value of the animated property, respectively, and prop for the property being animated.

Categories : Javascript

How to execute code with nunit at start only
Take a look at SetUpFixtureAttribute (more information here). It says: This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace. The class may contain at most one method marked with the SetUpAttribute and one method marked with the TearDownAttribute.

Categories : C#

MVC Default code to execute everytime
One thing you could do is create a shared layout page that all of your "menu-based" pages use. This shared page could be strongly typed towards your role model, which would allow you to check who the user is and what their permissions are prior to loading the content of the page. Im not sure how your model handles roles but from there you could stuff something into view bag, generate some chump html, etc etc so that your page knows what menus to load.

Categories : Asp Net Mvc

execute binary machine code from C
I got this done. The code must be marked as executable code. One way to do it is to copy this binary machine code into executable buffer. #include <unistd.h> #include <sys/mman.h> #include <string.h> char code[] = {0x55,0x48,0x89,0xe5,0x89,0x7d,0xfc,0x48, 0x89,0x75,0xf0,0xb8,0x2a,0x00,0x00,0x00,0xc9,0xc3,0x00}; /* * 00000000004004b4 <main> 55 push %rbp 00000000004004b5 <main+0x1> 48 89 e5 mov %rsp,%rbp 00000000004004b8 <main+0x4> 89 7d fc mov %edi,-0x4(%rbp) 00000000004004bb <main+0x7> 48 89 75 f0 mov %rsi,-0x10(%rbp) /NetBeansProjects/examples/tiny_c/tiny.c:15 return 42; 00000000004004bf <main+0xb> b8 2a 00 00 00 mov $0x2a,%eax /NetBeansProjects

Categories : C

Execute code after method has finished
You want to use the UIKeyboardDidHide notification and run your code in there. Here is the link in the docs... http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html

Categories : Iphone

using an asp.net button to execute javascript code
Does this work? OnClientClick="return (ValidateLogin())" That is assumint it returns true or false, if it returns 1 or 0 (1 for ok to submit) you can try: OnClientClick="return (ValidateLogin()===1)"

Categories : Javascript

determine the time taken for my code to execute in MFC
There may be better ways, but I do it like this : // At the start of the function LARGE_INTEGER lStart; QueryPerformanceCounter(&lStart); LARGE_INTEGER lFreq; QueryPerformanceFrequency(&lFreq); // At the en of the function LARGE_INTEGER lEnd; QueryPerformanceCounter(&lEnd); TRACE("FunctionName t = %dms ", (1000*(lEnd.LowPart - lStart.LowPart))/lFreq.LowPart); I use this method quite a lot for optimising graphics code, finding time taken for screen updates etc. There are other methods of doing the same or similar, but this is quick and simple.

Categories : Visual Studio 2010

ApplicationController how to execute code on each page
ApplicationController is the correct place, but you should put your code in a before_filter : class ApplicationController < ActionController::Base protect_from_forgery before_filter :ensure_setting private def ensure_setting @setting = Setting.where( id: 1 ).first or redirect_to( new_setting_path ) end end

Categories : Ruby On Rails

Execute code whenever a worksheet is added
Add your details to the workbook's NewSheet event: It is executed every time a new sheet is created.

Categories : Excel

Execute commands via C code in Android
The invocation is execl(path, arg0, arg1, ..., (char*) NULL); The second argument, arg0, is the name the program is told was used to invoke it. The actual arguments given to the program only start at arg1. So you should change your code to execl("/system/bin/screencap", "screencap", "-p", "<pic>", (char *)NULL);

Categories : Android

Ruby: Execute code for every subclass
In the ParentClass override the inherited method class ParentClass def self.inherited(subclass) execute_function super end ... end See: http://ruby-doc.org/core-2.0/Class.html#method-i-inherited

Categories : Ruby

Using codeigniter to execute code from another file
When adding Captcha in Fuel (a codeigniter based cms), I've put the php file that generates the Captcha image in the folder where you put images, then link to it the same way you link to an image: <?php echo img(array('src'=>'image_show.php', 'alt'=> 'CAPTCHA Image')); ?> Perhaps not the nicest solution, but it works. Alternatively, just use a Captcha plugin written specifically for codeigniter, such as the NuCaptcha CodeIgniter plugin, http://docs.nucaptcha.com/plugins/codeigniter.

Categories : Codeigniter



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