What's the difference between concat, uglify, and minify tasks in grunt? I set up an uglify task for all of my site's javascript tasks, and it seemed to both minify and concatenate them. Grunt's site has a great description for how to configure each task, but it doesn't seem to explain what each task actually does.
Concatenation is just appending all of the static files into one large file.
Minification is just removing unnecesary whitespace and redundant / optional tokens like curlys and semicolons, and can be reversed by using a linter.
Uglification is the act of transforming the code into an "unreadable" form, that is, renaming variables/functions to hide the original intent... It is, also, irreversable.
Concatenation - Merges all the specified files to create a new single file.
Minification - It simply means all the unnecessary white spaces and redundant optional tokens will be removed.
Example - self.description = 'Hello'
Minified version will be - self.description='Hello'
Uglification - It simply means converting the code in such a format that core logic can't be understand easily. To do the same it renames the variable and their references, it renames the parameter with shorter name etc.It simply obfuscate the business logic so that no one can easily understands it.
Example -
self.description = 'Hello';
function(self.description){}
Uglified version will be -
j.description = 'Hello';
function(j.description){}
Related
We're adding CodeClimate to a project and running into a lot of method-lines errors for the render functions in our React components,
example:-
Function render has 78 lines of code (exceeds 40 allowed). Consider refactoring.
We would like to filter out all our render functions from the method-lines check. We could increase the line threshold or disable the check altogether, but we still want the check for other functions, so that's not desirable.
There is node filtering for duplication checks, but I can't find anything similar for method-lines.
To exclude specific functions from the method-lines check in CodeClimate, you can use the method-lines.ignore configuration option in your .codeclimate.yml file. This option allows you to specify a list of regular expressions that match the names of functions that you want to exclude from the check.
For example, to exclude all render functions in your React components from the method-lines check, you could use the following configuration:
method-lines:
ignore:
- "render"
This will ignore any function with a name that matches the regular expression "render". Note that this will also ignore any function with a name that contains the string "render", such as myRenderFunction.
You can also use more complex regular expressions to match specific function names. For example, to only ignore render functions in a specific module, you could use a regular expression like this:
method-lines:
ignore:
- "moduleA/render"
This will only ignore functions with names like moduleA/render, moduleA/renderFoo, etc.
you need a codwclimate.yml file and you can change the threshold with the following - although having a giant render function isn't really great - i'd suggest keeping it under 50 lines as well.
version: "2" # required to adjust maintainability checks
checks:
argument-count:
config:
threshold: 4
complex-logic:
config:
threshold: 4
file-lines:
config:
threshold: 250
method-complexity:
config:
threshold: 5
method-count:
config:
threshold: 20
method-lines:
config:
threshold: 25
this is from the docs here: https://docs.codeclimate.com/docs/advanced-configuration#section-default-check-configurations
method-lines is the last one above - and please make sure to not cut/paste as the YML will need the indentation to be exact. Good luck!
My goal is to take some data from python and/or scala interpreter in Zeppelin, and to finally display the data inline by some JavaScript library such as Plotly, D3, Vis, etc.
The perfect seamless integration would be to simply output the JavaScript incl. the stringified data via print("%html <script>" + content + "</script>").
Indeed, this works very well with all kind of libraries as long as the content is not too large, e.g., print("%html <script>alert(JSON.stringify({name: 'Peter', age: 24}))</script>")
However, if the content size grows, then the html output takes very, very long, e.g.:
%python
print("%html start")
s = "X" * 100000 # data of length 100k
print("<script>js='" + s + "'; alert(js.length)</script>") # takes > 1 minute!
Note that if I write the same output to a file and load it, there is no such delay. Thus, it is not caused by slow browser rendering, but probably by Zeppelin's way how %html output is processed?
Does anybody know how to fix or circumvent this problem?
Okay, I finally found the answer: this is a known bug.
https://issues.apache.org/jira/browse/ZEPPELIN-1360
A workaround is to use the %pyspark interpreter for python development, rather than the pure %python interpreter.
I changed my handlebar template's extension and referred to the same in the function which called handlebarjs' compile function.
It worked perfectly fine with no issues.
But I'm curious to know if anyone else tried that?
Please let me know if you think this could cause problems down the road for any reason.
For some reason I feel that the very extension .handlebars is a bit long. I prefer to keep it to a max of 4 chars ... something like .txt or .html.
Please let me know if you see any issues with this approach.
For example, I renamed login.handlebars to login.html
In the getTemplate function (as shown below), I will call this template for compilation
function getTemplate(name) {
if (Handlebars.templates === undefined || Handlebars.templates[name] === undefined) {
$.ajax({
url : "templates/" + name + ".html",
success : function(data) {
if (Handlebars.templates === undefined) {
Handlebars.templates = {};
}
Handlebars.templates[name] = Handlebars.compile(data);
},
async : false
});
}
return Handlebars.templates[name];
}
My shop uses .handlebars, along with Require.js and Alex Sexton's require-handlebars plug-in, and it all works without issue. The far more common suffix however, and the default one in that plug-in I just mentioned, is .hbs (presumably because .hbs is a 3-character extension not already taken by another file type).
You can for example use .hbs, .handlebars, or even a different extension for that matter, and it should work just fine with any sort of library (eg. Require) where the suffix could actually matter. There are no guarantees of course, but because there is no official extension library authors generally know better than to hard-code one.
I would caution against using .htm or .html for these files though ... unless you have a really picky IDE. Most IDEs can be set to treat .hbs as if it were an HTML files, for syntax coloring and what not. If your's can't, then .htm might make sense. Otherwise I'd keep the file extension distinct, so that you can easily distinguish between the two types of files.
I noticed there is a bug in Croogo's NodesController::search() when searching for words with some non-ascii chars on them e.g. 'üäö'. If I search for example for 'Steuergeräte' (german) I get no results, even though I should. If I search for 'Steuergerate' (which would be misspelled in german) I get the desired results. Which is totally weird.
A direct query on the db I works fine:
"SELECT * FROM i18n WHERE content LIKE '%Steuergeräte%';"
Which returns the expected records.
But it's not a general problem with unicode-chars, as for example, searching for a japanese word worked as expected. So this only affect some chars.
Cakephp: 2.4.0, Croogo: 1.4.5
Ok, I found the cause of the problem.
On the search-view, the string to be searched for is cleaned with:
$q = Sanitize::clean($this->request->params['named']['q']);
Which among other things runs html_entities on the string as default, when 'encode' => true is set (default). This would turn e.g. ö into ö and then search for words with html-entities on them.
I got a workaround by doing:
$q = $this->request->params['named']['q'];
// Use encode=false on Sanitize::clean to prevent äüöß etc. getting
// replaced by html entities. And strip tags manually first to prevent
// html injected strings.
$q = strip_tags($q);
$q = Sanitize::clean($q, array('encode' => false));
Note: If like in my case, TinyMCE is set with 'entity_encoding' => 'raw' then the body field in the nodes table would contain äöü instead of htmlentities as well, which IMO is a far better practice as replacing them with htmlentities. Per default though, tinymce replaces chars with htmlentities, so the body field would work with the default search behaviour of Croogo/Cakephp. But searching, for example, in the title-field wouldn't.
Update
Ok, as mark comments suggested, sanitizing and using cake's paginate method, is not necessary, so the Sanitize part can be skipped. I also found using htmlspecialchars even better as strip_tags, as strip_tags wouldn't take care of e.g. '&', and on the body, tinyMCE saves those as html_entities. So the updated code would look like this:
$q = htmlspecialchars($this->request->params['named']['q']);
// go on with searching for nodes on paginate-method
How would one concatenate a symbol with text on either side?
For example:
Prefix: "GAR_"
Variable: $todayDate
Suffix: "_1"
GAR_$todayDate_1
Which would evaluate to:
GAR_07202012_1
When running the test in fitnesse, it seems as though the concatenation is working (GAR_$todayDate->[07202012]_1). However, I am passing this value as a parameter to visual studio and I instead end up with the following text: GAR_$todayDate_1.
When I remove the suffix or put a space between $todayDate and "_1", everything works as expected.
Any help would be appreciated.
Things I have tried:
GAR_!-$todayDate-!_1
GAR_$todayDate!-_1-!
GAR_$todayDate${SUFFIX} - static variable defined
Thanks,
Mike
I am stuck with the same problem currently.
The only way I found was to:
create a StringSupport class with a String concatenate(String s1, String s2) method
import the package of that class in your FitNesse test
put StringSupport in the available libraries in your FitNesse test with the Library table
in your Script, you can now do: |$result=|concatenate;|$s1|$s2|
To fit your exact use case, you just have to do the same concatenate() with 3 strings instead of just one.