# Tag Info

19

You don't have to inject express into each modules. requiring express in each file will return the same instance. http://nodejs.org/docs/latest/api/modules.html#modules_caching Also, ask yourself who should be the one registering the router into the app. The app it self or the router ? For code reuse and clean separation you should let the app handle it. ...

19

An ImportError instance doesn't have a replace method. You can use e.name instead of messy string replacements. Instead of '%s' % x, it's recommended to use '{}'.format(x). The example output is not what you posted, but actually this: 'Error: Try sudo pip install Crypto' That is, it's surrounded by single quotes, because you wrote as "'some text'". ...

14

Since the classes are all subclasses of _MyBase, they can be accessed via _MyBase.__subclasses__() after they have been imported: for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]): importlib.import_module('.' + name, __package__) all_my_base_classes = {cls.__name__: cls for cls in base._MyBase.__subclasses__()} For importing the ...

11

First of all, this code doesn't work. e is an ImportError instance, not a string, and so it doesn't have a replace method; you want to operate on e.msg instead. Secondly, the messages generated this way will be wrong a non-negligible number of times, as modules aren't always available in PyPI packages of the same name. The bs4 module is in the ...

9

Approach 2 does not work because accoring to MDN: import '/modules/my-module.js'; Is how you import a module for Import a module for its side effects only Import an entire module for side effects only, without importing anything. This runs the module's global code, but doesn't actually import any values. So, await import('/path/to/my-module.js'); won't ...

7

I'm the lead engineer for the MongoDB Perl driver with a couple of thoughts for you: you're using 'authenticate', which is for a very old version of the driver which is not recommended for use. In the v1.x series, you should provide username/password in the URI or in MongoClient parameters. Most of the value of this module seems to be setting parameters ...

6

I am not even remotely familiar with lua or how it works with Objective-C, so I can't really comment on any of these aspects of your code. What I can do of course, is comment on the Objective-C bits, starting with your header file. Why is there anything in your header file at all? #import <UIKit/UIKit.h> #include "lua.h" #include "lualib.h" #include ...

6

Nice work! I presume the complicated way of getting the right element measurements is to cater for many browsers, won't comment on that. I would add some comments on the nature of the 'magic number' scope.triggerOffset = 150; or, better, encapsulate it away as .constant or offer as configurable option, to make your directive more re-usable. I find the use ...

6

There's a lot of code here, so I'm just going to review bitex.utils. You'll see that there's plenty here for one review. Maybe some of the other reviewers here at Code Review will review some of your other code. There is no module docstring. What is the purpose of this module? What does it contain? import requests is in the "Built-Ins" section but as far as ...

5

There are few ways to solve your problem with Backbone.js + Require.js and executing functions or changing routes from view. 1. Using Backbone.Router Here is approach I've used multiple times: 'use strict'; // Your view -------------- define([ 'jquery' 'backbone' 'common/views/view', 'common/helpers/misc' ], function ($, Backbone, View, ... 5 document.querySelector While it is a great function to use, you are using in the wrong situations. For every time you use it, you are getting an array of elements with a class that you passed in to the function. Why not just use document.getElementsByClassName? Sure, it takes a little bit longer to type but it's faster. This about it: the querySelector ... 5 A couple of simple things I notice right off the bat. If you have a method which only calls another method, why bother having the first method at all? I'm personally against these one-line wrapper methods and see them as unnecessary noise. Your methods should be verb phrases, in general (e.g., CollisionHelper.helpCollision or even performCollision, in this ... 5 module.exports is just an object. Set properties on it that you want to expose. exports.add = add This is also equivalent in this case. module.exports = {add: add} Now, when you require this module, you'll get an object with one property: add. There are a few other small issues: Nothing about your design depends on accessing methods via this. This ... 5 Personally, I'd prefer to use @export() or @export(globals()), rather than manually perform the @ sugar. I don't like using __globals__, even if it is writeable. Honestly, I think the cleanest solution would be to abuse lists, and use a closure. I do however agree that inheriting from Exception, is the best parent to inherit from. And so I'd personally use ... 5 Missing Error Checks Always check user input, you are doing this correctly in the function scanMatrix() but you missed the check on order before scanMatrix() is called. Prefer return EXIT_status; Over exit(EXIT_status); There are a number of functions that call exit(EXIT_FAILURE); In a small program where only one person is doing the program it's very ... 4 Using exec() is generally regarded as bad practice (https://stackoverflow.com/questions/1933451/why-should-exec-and-eval-be-avoided). Since you are trying to import a module, you can do the same by using the importlib package. Python 2: https://docs.python.org/2/library/importlib.html Python 3: https://docs.python.org/3/library/importlib.html#module-... 4 I'm an experienced Java programmer who, upon realizing Java applets don't run in browsers anymore (I know I'm late to that party!), decided to bite the bullet and move to JavaScript. Yay! Welcome to JavaScript, where everything looks broken! >:D I'd love feedback on how to save time with intellisense developing a single-page requirejs or any other ... 4 You've got a security vulnerability here just waiting to be exploited based on the fact you use the same interface for "The human" and "The Filesystem". All you need is for somebody to create a file with: open my$fh, '>', 'path/*' And that will get glob-expansion during traversal. Which means you DON'T want to use glob at a level other than the user-...

4

The names 'txtX' and 'txtY' don't say anything about the domain as 'line', or 'length' do. Someone would need to see how are you using that variable to figure out what it is. If you want to make the code more readable, make explanatory variables and helper descriptive methods for example bool fitsInCurrentLine = col+dx<=maxCol; if( fitsInCurrentLine ) ...

4

There are a couple things you can do here to make things simpler. The first is to make your inner loop a while loop instead of a for loop. With this idea, you can build up each number char by char, using Character.getNumericValue() which will return 1 for '1' etc. With charVal, we can incrementally build up our number by multiplying the by 10 and adding the ...

4

I want to know if the way I format my for loops and if else statements is good style. On the whole, yeah, looks good. I recommend you use braces for one-liner blocks as well. In this instance, I'm not batting an eye at it—it's fine—but it's a good habit to learn. I was wondering if I could do this without count. Yes, since count = j - i, you can elide ...

4

Since no one else has replied, here's somewhat of a "rubber duck code review" given that I don't know much about Windows, vt, and NativeCall. Plus I've got a suggestion about the API and module name. It looks like the not-explicitly-initialized $input-mode and$output-mode variables are actually constants implicitly initialized to zero. I think the code ...

4

Toward optimized functionality and design since all crucial attributes x, y, x_mean, y_mean are initialized on LinearReg instance creation (within __init__ method) - no need to duplicate and define them as class attributes (x = [] ... y = []), those should be removed as redundant raise Error - Error is not Python exception class. Use Exception or ValueError ...

4

Don't hide pointers Don't hide pointers in a typedef: typedef struct moduleIF_CTX *moduleIF_CTX_t; This makes it really hard to spot when things are passed by value or by pointer in the rest of the code. You could make it more explicit: typedef struct moduleIF_CTX *moduleIF_CTX_ptr_t; But I would just do this: typedef struct moduleIF_CTX moduleIF_CTX; Yes,...

3

A few small comments: The error message looks wrong to me. This is what the logic looks like to me: if (third party package is installed): install(in-house package) else: install(in-house package) install(in-house variant of third-party package) but the printed warning tells me that the in-house package isn’t installed. Shouldn’t it tell me ...

3

Binary Indexed Tree is a suitable data structure for this question. However, you have to be careful of how you want to use it. For me, I would use it for storing values of "Functions". Based on the code you posted here, it is difficult to tell if you modularized it properly. However, since you said it works for small input, then I believe that you have coded ...

3

What you're looking for in your cache decorator is functools.wraps. Otherwise, very handy!

3

I also hate large files. My rule of thumb is a maximum of 300 lines per class. You mentioned that you wanted to put methods in helper classes. Also you said you were not sure about refactoring patterns. Use the simplest refactoring: OO! You should not just break things into helper methods and helper classes, but into real classes. You have a full page ...

3

This is nowhere near the full answer, but I just want to touch on the initialize method of Merge real quick since it was the first thing to jump out to me. def initialize(destination_id, *source_ids) @source_ids = source_ids @destination_id = destination_id @sources = Modelname.where(id: @source_ids).all @destination = Modelname.where(id: @...

3

Note that isSorted has a bit of an off-by-one error. It will check outside the bounds of its argument. This actually works OK, because it compares the last element of the array to undefined which always results in false. However, you should really only check up to index_outer < length - 1. I haven't looked too closely at your implementations of the basic ...

Only top voted, non community-wiki answers of a minimum length are eligible