w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Good programming etiquette/ good programming practices
Val is a left over Legacy function. I would recommend switching to type specific converters. This also provides protection for values that are not convertible like letters. Remember to convert types. Turn Option Strict On and you will see. Integer.TryParse Dim result As integer = 0 Dim numberA, numberB as Integer If Integer.TryParse(TextBoxNumbA.Text, numberA) Then If Integer.TryParse(TextBoxNumbB.Text, numberB) Then result = numberA + numberB End If End If TextBoxResult.Text = result.ToString("n2")

Categories : Vb.Net

A good programming language is a conceptual universe for thinking about programming
The meaning of this quote is: What we need is not just another programming language but a conceptual universe for thinking about software development, embodied in a kind of language that is new to computer science -- a language that will bridge the gap between programming and software development at large.

Categories : Misc

Is it good programming practice to use shell scripts in systems programming
You're running the shell script from within code in another language? In that case using a shell script is almost certainly unnecessary. Virtually all languages allow you to run an arbitrary command and capture the output. For example, C and friends have popen() and Perl, Ruby and such have backticks (`lpstat -a` returns the output of that command as a string). This kind of approach makes it unnecessary to have an extra shell script or a temporary file.

Categories : Bash

How to convert Text-based programming code (stored in DB) into actual programming code?
The hard way is to interpret the code within the database, the easier way is to store c# code and runtime compile it with CodeDOM http://msdn.microsoft.com/en-us/library/y2k85ax6.aspx Or take a look at Iron Python. http://ironpython.net/

Categories : C#

How to manage an event in android programming
Android use a system of callbacks to manage these sort of events (click, touch, etc.) For example, when you click on a button btnMyButton, the framework will check if there is a OnClickListener attached to it, and if so execute its onClick() method. Listeners methods usually take a View argument so you can use the same instance for several Views, and adapt the behavior depending on the affected view (usually using View.getId() ) the android:onClick is just an XML shortcut which can be handy for tiny apps. For bigger application, I believe it is clearer and less error prone to use View.setOnClickListener() instead.

Categories : Java

Asynchronous Programming - It's good But who did that?
Dear O/S can you read this file for me and when you have done it just call that callback! That's it, basically. Async IO uses OS kernel facilities to register a callback with an IO. While the IO is running there is no thread in use at all. Not even a background thread. The callback runs immediately inside of the node process, and queues a work item to the event loop.

Categories : Node Js

What is a good way to manage several audio sources loaded by MediaPlayer in Android?
You should take a look at SoundPool class, i think is way better suited for what you are trying to do, here is a good example of how to use it: http://www.edumobile.org/android/android-programming-tutorials/sound-pool-example-in-android-development/ SoundPool is perfectly suited for games, i've used it in mine and works perfect, the class allows you to, easily loop, play, and stop several sounds simultaneously, without creating one MediaPlayer per action, all you need to worrie about is to release the pool when you are done with it. Also depending on what you are doing it has a very efficient priority system, that allows you to set a max amount of sounds to play and based on priority let another sounds continue playing and taking resources of another sounds when inserting new ones... Do

Categories : Android

Are nested try/except blocks in python a good programming practice?
In Python it is easier to ask for forgiveness than permission. Don't sweat the nested exception handling. (Besides, has* almost always uses exceptions under the cover anyways.)

Categories : Python

IOS programming: Passing large arrays over segues, good or bad idea?
I don't really use storyboards, but a quick look on google pointed to something: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"showRecipeDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; RecipeDetailViewController *destViewController = segue.destinationViewController; destViewController.recipeName = [recipes objectAtIndex:indexPath.row]; } }

Categories : IOS

Git strategy needed to get an old source code in Git and manage it to have a single point to maintain code
The usual way is to create a repository for each codebase. Putting unrelated code into one big repository dilutes the benefits of source control. Following your comment I think what you should look at are git submodules. It gives you a single repository which you can share with other repositories. Also, if you make a change to the common code in one project you can push this to the master repository where it is the available to other repositories should they wish to use the changes.

Categories : GIT

Inheriting Doctrine Models to keep autogenerated code separated from custom code: good idea?
Am I wrong saying that you could use entity repositories for your business logic? http://www.masnun.com/2012/11/12/symfony2-doctrine-custom-entity-repositories.html

Categories : Symfony2

Reveal.js server - serve many presentations
As long as you're using basic features you don't need node.js at all - just drop the reveal.js distribution in every presentation folder where it is served statically. Another option is hosting on github pages, I've checked it now for this scenario and it seems to be served right. You might also want to raise this issue at the project page https://github.com/hakimel/reveal.js/issues

Categories : Node Js

how to make an android phone "as good as new" for practising android programming
Yes, restoring factory settings and formatting SD card is more than enough for making your Android phone "as good as new". I reset my Android (testing) device every month to keep it performing as good as new.

Categories : Android

Presentations: Intellij/Cipboard macro at human typable speed
Some people create ad-hoc live templates for their presentation that insert the whole code snippets for them. It's not human speed though. You could try to create a small plugin with a single action which does Thread.sleep(...) synchronously and invoke it in your macros to slow them down. It's a bit tedious though. You can split your live templates or macros in small chunks and comment after invoking each of them. This should add some continuity to the presentation and not let your listeners lose the focus.

Categories : Intellij Idea

Manage devices from code (C#)
I recently did a project on the Wiimote, faced the exact same problem you're having. I found a program named WiimoteConnect: This little program automatically handles all the install/uninstall bluetooth connection stuff for you.

Categories : C#

Good practice to code partition
Validation normally belongs to the service layer, as there is no need to tie it to a specific view implementation. So in your case try to put it in the EJB. If you have to implement another application which is to use another view implementation like Swing for example, it will benefit from the validation as well. It's normally easier to write tests against the service layer; and this way you can test the validation without having to mock the view layer. Using JSF, if you have two use cases using different managed beans, and both use cases create a user, chances are that you end up with writing the validation code twice.

Categories : Java

Is this a good candidate for using async await in this C# .NET code?
If all you want to do is to execute the two operations in parallel, then you don't need async-await. You can use old TPL methods, like Parallel.Invoke(): Parallel.ForEach(animals, animal => { Parallel.Invoke( () => animal.Owner = GetAnimalOwner(ownerId), () => animal.FavouriteFood = GetFavouriteFood(foodId)); Database.Store(animal); }); Keep in mind that there is no guarantee that this will actually improve your performance, depending on your DB and your connection to it. In general, async-await makes sense in two cases: You want to offload some long-running code from the UI thread. You want to use less threads to improve performance or scalability. It seems to me like #1 is not your case. If you're in case #2, then you shou

Categories : C#

MS-SQL - Is it possible to manage the code of sql agent jobs using the Visual Studio SSDT plugin?
At the moment, there's no good way to handle this. Jobs are made up of data stored in the tables in msdb. The best way to handle it would be either to script out each job into its own file, then call those from one larger file or to make a single large file of all scripts for the jobs. I'd probably look into scripting out each job into its own file and calling them from a larger script. It would be more manageable in the long term and you could easily comment out a single job by commenting it out of the main script. There's no way to compare/update the jobs directly, though you could possibly use a Data Compare tool to check the various job tables in msdb against some master copy of the data. SQL Data Compare from Red-Gate is probably your best option for that as SSDT does not include da

Categories : C#

What is a good method of doing TDD with legacy Delphi code having embedded SQL
In your place I would use DUnit to create a unit test project. For each of the entities I would write testing methods that would run the old and new sentences and then write methods to compare the results. I would write a TTestCase class named, let´s say TMyTestCase, and add some helper methods to it, then would create my new test classes as subclasses from TMyTestCase. The idea of the ancestor class is to provide common functionality that makes it easier to write the tests (the comparison methods, for intance) in order the enhance productivity and comfort.

Categories : SQL

Is this ruby-on-rails rspec code good practice?
Doing that is pretty much just "wrapping" the syntax, I don't think it really adds much to the code. The code you had earlier wasn't too bad, but perhaps you could also consider doing this: expect { click_button submit }.to_not change{User.count}

Categories : Ruby On Rails

Is it a good style to modify a preprocessor macro in the code?
It gives you a warning because most of times it's unwanted: you're assigning a value to an existing macro because you didn't know it exists. When you have to do it IMO is much better to be more explicit (to let the preprocessor know it's not an error and to make it clear to human readers too): #define VALUE 1 #undef VALUE #define VALUE 2 #undef VALUE #define VALUE 3 Just for information you may even disable that warning using #pragma GCC diagnostic ignored but even in that case you'd better to write something to explain the reason. That said you may consider to review your design, I can't say something better without more information about your code (or about what you want to achieve) but if you need such trick probably a little refactoring will make everything much more clear.

Categories : C++

Is encryption a good method of protecting your java code?
the answer is: Not in java! When you pack your programm into a runnable jar-file, all your classes are in there. but as byte code! Reversing that byte-code to java file is possbile but not that easy to read.

Categories : Java

How to manage and selectively stop a published subscription from Meteor server side code
Create two separate subscriptions that both return game data. One subscription should return public game data, the other should return game data that is viewable by the currentUser. They will be merged into one collection on the client side. Games the user has joined will contain private info AND public info, games they haven't joined will only contain public info. Then on the client side, a liveQuery like Game.findOne(thisGame.id) will automatically receive the private information when the player joins the game and cause your template to be re-rendered, etc. Pseudo-code for illustrative purposes: if Meteor.isClient Meteor.subscribe 'GameInstances' Meteor.subscribe 'MyGameInstances', guestId join = (gameInstanceId, spot) -> Meteor.call "join", gameInstanceId, spot, (er

Categories : Meteor

Can`t run Python code computing Fourier Transform on .tiff image? How to manage memory?
Some suggestions: The scipy.fftpack functions allow you the option of overwriting your input array (overwrite_x=True), which may buy you some memory savings. You could also try anfft (or the newer pyFFTW), which is just a Python wrapper around the FFTW C libraries. It's definitely much faster than the numpy and scipy FFT functions, and at least in my hands it seems to also be a bit more memory-efficient. Could you maybe cast your array to a lower bit depth (float64->float32, uint16->uint8)? You could always downsample your image first (e.g. using scipy.ndimage.zoom). Reducing the spatial resolution of the image will of course reduce the spectral resolution of the FFT, but it might not matter that much to you depending on what exactly you want to do with it. Buy some more RAM?

Categories : Python

Exists a nice python wsgi to manage MYSQL database locally ? or must i code one myself?
If you don't like phpMyAdmin as it is quite feature loaded and heavy, you might be interested in Adminer, which is made to be more lightweight. Though this is still in PHP...

Categories : PHP

convex hull code of "competitive programming 1"
If I understand your question correctly, you want to know why the sort function is important? It is because your code there uses Graham's scan, a method for finding the convex hull. In order for Graham's scan to be more efficient, the points must be sorted by their angle relative to a fixed point. The angle_comp function compares the angles of the two points A and B relative to the pivot point. This function, when plugged into std::sort, allows us to sort all the points around the pivot based on their angle relative to or distance from the pivot. For two points A and B around a pivot. If point A and B have the same angle, or if one of the other both are near the pivot, than we need an alternative way to sort the two points. We sort the points by their distance from the pivot instead. El

Categories : C++

Python MySQLdb - Programming Around SQL Injection Code
RandomSeed posted the correct answer to my question so I'll repost: SQL injection becomes possible as soon as you start integrating user input into your queries. This is one of the most famous illustrations. This reference question, although initially appying to PHP, also provide tons of valuable information on how to prevent this, regardless of the language

Categories : Mysql

Event Driven programming - non linear code
Like this: var done = function() { msg = 'done'; }; fs.open('fp.txt', 'w', 0666, function(error, fp) { if (msg == 'say') { fs.write(fp, 'Hello world!', null, 'utf-8', done); } else { done(); } });

Categories : Node Js

Better programming - generic or multiple code in methods
You might consider implementing the Template Method Pattern. You create a base class that does all the general work (in some DoIt method) and delegates the setting of the gain to a abstract method (SetGain) that needs to be implemented by all the subclasses. This might look a bit like overkill, but if you choose the names of the subclasses well, it might be more clear what the code is supposed to do. In a modern language like C# this pattern could very well be implemented using a lambda or a delegate or Func<> as @X.L.Ant suggested.

Categories : C#

Page doest not work good in JavaScript code with form
Please see the demo here there are several mistakes in this line div_new = div_new+"<form name='"+name+"' onsubmit="+ return refresh(name, url, document.forms[name][name].value , '', '', 'refresh'); +" method='post' style='display:inline;'>"; Use this code function chat(mem_id) { count++; var div_new = "<div style='position:absolute; width:200px; bottom:0px; left:10px;'>"; div_new = div_new+"<div style='width:100%; background-color:green;'>top "+ mem_id +" - "+count+"</div>"; div_new = div_new+"<div style='width:100%; height:300px; background-color:pink;'>bottom // refresh_chat"+ mem_id +" "; var name = "send_chat_"+mem_id; var url = "send_chat.php"; div_new = div_new+"<form name='"+name+"' onsubmit="return ref

Categories : Javascript

C/C++ (Other Languages Too?) Conditional Early Return Good Code Practice
The else would only add clarity if the else clause is short, a few lines of code at best. And if you have several initial conditions you want to check, the source gets cluttered very quickly. The only time I would use an else if it is a small function with a small else, meaning less than about 10 source lines, and there are no other initial checks to make. In some cases I have used a single loop so that a series of initial checks can use a break to leave. do { ... } while (0); I am loathe to use a goto which is practically guaranteed to get at least one true believer of goto less programming up in arms. So much would depend on any code standards of your organization. I tend to like minimalism so I use the first version you provide without the else. I might also do something li

Categories : C++

need explanation in structure C programming, doesn't understand code
rec1 and rec2 are two variables you have created with that struct abc type. You could just as easily separate the structure specificion from the variable creation with: struct abc { char name[20]; int studno; float tax; }; struct abc rec1, rec2; If you were to define a variable as: struct abc *rec3; then rec3 would be a pointer type which was meant to point to a variable of type struct abc.

Categories : C

Celery task executing code from another programming language
You can use Celery HTTP Callback Tasks (Webhooks) http://docs.celeryproject.org/en/latest/userguide/remote-tasks.html

Categories : Python

PHP programming challenge - code generator wont accept
# so... this works well enough $arr = array(array(141,5651,161), 2, 45446, array(101, 202, array(303,4))); print MaxArray($arr); // outputs 45446 print " "; # but now...let's try it again. In the same script. *gasp!* $arr2 = array(42); print MaxArray($arr2); // outputs 45446 (!!!) The problem is that static variable; it isn't getting cleared between calls to the function. So previous results affect future ones. This is almost certainly incorrect, and would certainly cause a knowledgeable human judge to reject your code. Get rid of the static variable. You can pass it as an argument, you can simply compare with subresults like the other answer here was suggesting... or you could show off with a closure and array_walk_recursive. :) function MaxArray($arr) { $max = -1; a

Categories : PHP

Is there a good PHP editor with user defined/custom code completion for MacOS?
I, and many others I know, am a huge fan of PhpStorm and believe it's well worth the money. Great code completion that also recognizes PhpDoc Awesome debug support Integrates well with VC Easy to install plugins that add support for myriad things. e.g. LESS, SCSS, CoffeeScript, NodeJS, much more. A ton of other useful features Check out the trial, spend a little time configuring the settings. e.g. I've added many live templates, set up PHPCS, code style, etc. Become familiar with the keyboard shortcuts for quickly navigating/finding files & symbols (objects, methods, functions) Cmd+Shift+N, Cmd+Shift+Alt+N. Pretty sure most of that is in the Quick Tips dialog.

Categories : PHP

API development, Bootstrap and jQuery. Good idea to inject them all in user's code?
If you have to have jquery and bootstrap, the only acceptable solution for an embeddable widget would be an iframe. You could write a loader script which places the iframe with your main content onto the page. I've written a quite extensive article about how to build embeddable widgets and their best practices on my blog here: http://codeutopia.net/blog/2012/05/26/best-practices-for-building-embeddable-widgets/ (based on a Stack Overflow answer I gave some time ago, but couldn't find the link to it)

Categories : Javascript

Is it a good idea to include a large text variable in compiled code?
What you describe is by far the norm for C/C++. For large amounts of text data, or for arbitrary binary data (or indeed any data you can store in a file - e.g. zip file) you can write the data to a file, link it into your program directly. An example may be found on sites like this one

Categories : C++

Presentations.Open requires PowerPoint 2007 to be open?
In the event that it needs Powerpoint launched, I would just trigger the launch as part of the vbscript Set WshShell = wscript.CreateObject("wscript.Shell") WshShell.Run "C:Program Files (x86)Microsoft OfficeOffice12POWERPNT.EXE" You could build in some error handling to see which version is installed, and call the appropriate exe file

Categories : Vbscript

My code is giving runtime error! i am new to android programming can anyone tell my mistake
You get a ClassCastException because you are casting your TextView to a Button here: display = (Button) findViewById(R.id.tvDisplay); You need to cast it to a TextView: display = (TextView) findViewById(R.id.tvDisplay);

Categories : Android

Any good ways of quickly auditing code in a source control compared to production?
Since SSRS and SSIS are XML files, you could compare the text with the source code. It sounds like you might need to create your own custom code to compare. Some questions I would have when doing something like this: Are the production files in a similar folder structure to the source code? Is there a standard naming convention for files? Is a source file's name unique? In .net you can do some file comparison, if you need difference sets, you might look for a tool/library you could use.

Categories : SQL



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