I'm trying to calculate password entropy in ColdFusion (I know I could do it in JavaScript, but I like everything to work on the server as well as the client). In order to do so I need to be able to do a Log Base 2.
ColdFusion has a Log() function for a natural log and a Log10 for a Log Base 10, but I don't see any function that lets me determine the base for the Log.
I assume that I need to drop down to Java to do this, but I am not sure the best way to do that.
if you do log(x)/log(2) this is equivalent to log base 2 of x
Related
I build program, when in one part I have some ranking, and I would like to give users option to customize it.
In my code I have a function that gets objects and returnes them packed with points and position in ranking (for now it calculates the arithmetic mean of some object's values).
My question is is it possible to give e.g. admin chance to write this function via admin panel and use it, so if he would like to one day use harmonic mean he could without changing source code?
Yes, you could just store a string in the database and exec() it with suitable arguments...
However, you'll have to be careful – Python code can practically never be sandboxed perfectly. In the event that you accept any arbitrary Python code for this, and someone with nefarious intents gets to your admin panel to change the expression, they can do practically anything.
In other words, don't use raw Python for the code you store.
Disclaimers:
This is oriented towards Prestashop 1.5 but if the answer is: "this
is fixed in version 1.x" then I'll raise a petition to update our
shop.
I'm also tagging it as REST because I think I explained it throughly
enough so you don't need actual experience with Prestashop to understand it.
So in Prestashop we have this Web Services which lack support for use cases as simple as search by category.
1. Let's say you want to get all the products from categories 1, 3 and 17:
So what is the solution?
Well, you can do something in the lines of this answer: https://stackoverflow.com/a/34061229/4209853
where you get all the products from categories 1, 3 and 17 and then you make another call for products filtering by those ID's.
'filter[id]' => '['.implode('|',$productIDsArrayIGotBefore).']',
it's ugly and 20th centurish, but well... if it gets the job done... except it doesn't.
You see, this is a call for getting a resource, and someone somewhere decided:
Hey, we have all this nice HTTP action verbs, so let's use them for REST CRUD interfaces: POST for C, GET for R, PUT for U and DELETE for D. Neat.
And that's nice and all, but when combined with the lack of expressive power of Prestashop's Web Services means it's stupidly easy to run into, you guessed it? Yes, 414.
Error HTTP 414 Request URI too long
and we all know that modifying Apache so it accepts longer request URIs is not the neat scalable solution.
So we could try to split the array and make multiple calls, which is just conceptually ugh. Not just because of the performance hit of making multiple queries, but also because we would need to take into account the number of characters of all IDs concatenated to make the calculation of how many we can (safely) ask for in one call. And all that would have their own caveats, like:
2. What if we want to also filter them e.g. active=1?
Now we're in for a ride, because we can't know beforehand how many calls we will need to make.
Let's define:
N are the IDs I got from categories
n is the number of IDS I can safely ask for
T is the number of (filtered) products I want
tare the (filtered) products I already have
k are the (filtered) products we receive from the call
So we would end up with something like:
do{
n0= max(T-t, n);
k= get(products, n0);
t +=k;
}while(count(k)!=0 and count(t)<T and !empty(N))
..which is just... bonkers.
The only elegant solution I can come up with is creating a new Prestashop Web Service that acts as a wrapper, receiving the petition through POST and forwarding it to the Prestashop service.
But, befores that... do you have a better solution using some kind of RESTomancy I may be missing?
I started using cppcms to make a simple website + "service" that gets its input from the path like:
/maindb/2012/11/2/finalists/....
now i noticed that the nice url handling has only a regex dispatcher up to 4 parameters that will be given to the called function and a function without regex gets nothing at all not even the path.
Now what is the most feasible way to realize more than 4 parameters / subfolders.
Do I have to write my own url handling and if so where do i get the url from?
Is the url class public enough to iherit it and just extend it easiely for longer functions?
Or is there some other way how I am supposed to do it? (because 4 parameters seems kinda very less)
Two points:
If you have subfolders you are probably looking for organizing your URLs into hierarchy. See
http://cppcms.com/wikipp/en/page/cppcms_1x_tut_hierarchy
If you need more then 4 parameters you should:
Check if you really organize your application right (see above)
Combine several cases into single regex and split them afterwards in a parameters
For example (/\d\d\d\d/\d\d/\d\d)/(\w+) where the first would mach the data and not separatly year, month day.
P.S.: Url dispatcher is not designed to be derived from.
I am logging db information to a file, but what I would really like to do is see the code that produces each query, or at least the file/line number.
Is there a way to do this? Using filename/funcName/etc (see http://docs.python.org/library/logging.html#logrecord-attributes) only log the lower level files/functions (i.e. 'execute' in 'utils.py', instead of my code).
The SQLCompiler is located at django.db.models.sql.compiler
You can poke around in there. Some of what is there gets delegated to the other helper files in the sql folder and some others get further delegated to the base file in the respective backend.
You could probably attempt to log the variables as they come through those particular points.
I'm curious though, why?
You should try Django toolbar which is can give you sql queries for a page with backtrace and timings too.
I have a little problem with using Flex 4 with Coldfusion 9. I hope you can tell me what I have to fix.
I use Coldfusion 9, hosted on my development machine.
I created a table in MySQL database with 2 columns: idPlayer as integer and auto increment. 2nd column is Name.
I use a ColdFusion Builder, Apptacular, to generate solid CFC service for me. It generates PlayerService.cfc here.
Now I use Flash Builder 4's data wizard to generate data service class from PlayerService.cfc. I create a form on update method of that service.
Ok, now look at the generated code.
// Please uncomment the below line if Data Management is enabled for Player and update is used as the create function.
// var player:Player = new Player();
So I uncommented the code and run the form. After fill the data, and click update, the pop up appear like this:
Unable to invoke CFC - Field 'idPlayer' doesn't have a default value
For details, turn on Robust Exception Information in the ColdFusion Administrator
So I don't know how Apptacular generate the code to work as ORM. But it should have some way or workaround to let the system act with idPlayer has no default value to insert other columns and generate idPlayer as auto-increment value (as I set in MySQL).
Could you help me solve this?
I don't know what your Player.cfc looks like (that's where the error is actually happening), but you'll need to set the generator attribute of the id property to let Hibernate know that the database is supposed to take care of that for you. You'll most likely have the exact same error if you tried to save the object via ColdFusion, so test your Service using CF first, and then move onto Flash so that you know if your issue is really with your Flex integration, or with your CF app.