Use flow logic to skip a step in Transloadit assembly? - transloadit

Is it possible to use the flow logic or file filtering in Transloadit to convert a PNG to a JPG if the uploaded file is not already a JPG, but skip the step and continue with the other processing steps otherwise?
From what I can see from the docs, you can only halt an assembly if a condition is or isnt met..
Thanks!

You can use the /file/filter robot to pass :original files only to an /image/resize step if it matches your conditions.
You should disable error_on_decline to make this filtering seamless.
Here's more information on the /file/filter robot and here are all the variables you can use to filter by.
Looks like you could use either ${file.ext} or maybe ${file.mime}
Hope this helps!

Related

How to convert PDF to PDF/A-1a using ghostscript? What conditions are needed to convert to PDF/A-1a?

I already did a lot of research and realized that clear information about "How to generate PDF/A-1a" or "...convert to PDF/A-1a" is really rare. I found some information to convert to PDF/A-1a via GhostScript, but I didn't make it to get it working. So, maybe there are some necessary conditions for the data missing in the first place. Conditions like propper metadata of the PDF, structured data for readability by a screen reader, alternative text for pictures, and a declaration of the given language of the text. I need a proper working GhostScript command with the corresponding gs version and the mandatory file conditions to generate or even convert to PDF/A-1a. PDF/A-1b means nothing to me because I'm already able to convert to that.
Thanks for any help.

conditional include in asciidoc

I am using Spring RestDoc together with AsciiDoc to describe my rest api. RestDoc generates different files depending if there are request parameters described / response fields etc. I would like to have one template conditionally including whatever file exists.
something like this:
Request:
include::{reqresPath}/http-request.adoc[]
Response:
include::{reqresPath}/http-response.adoc[]
Parameters:
ifeval::[{{reqresPath}/request-parameters.adoc}.exists]
include::{reqresPath}/request-parameters.adoc[]
endif::[]
ifeval::[{{reqresPath}/request-parameters.adoc}.exists]
include::{reqresPath}/request-parameters.adoc[]
endif::[]
or at least exclude warnings in case of a missing file. But I could not figure out how to suppress these.
As of today, where is no operator for ifeval available, which can be used to check the existence of a file.
The way I would go is to write an extension for Asciidoctor, which can also be done by using Java. If your projects is big enough, I would suggest to go for this solution.
The most extreme way is to make a custom TemplatedSnippet which is generating an empty snippet to be included...
I hope there is a better way to do this.
Edit:
Take a look of http://asciidoctor.org/docs/user-manual/#by-tagged-regions

Shell Code inside a jpg file

I have seen that it may be possible to run shell code in a jpg file. Is this true?
I just want to start cmd through a jpg.
Or are there any other extensions where this would be possible?
Thank you!
Yes, it is possible to do what you asked, eventually all file types are just a set of binaries, if you know and control the format, you can basically do anything you want. It is a low level implementation and requires deep knowledge of the format, header and execution type.
For further reading I recommend you this article:
http://archive.cert.uni-stuttgart.de/bugtraq/2004/09/msg00316.html

Eliminating code duplication in a single file

Sadly, a project that I have been working on lately has a large amount of copy-and-paste code, even within single files. Are there any tools or techniques that can detect duplication or near-duplication within a single file? I have Beyond Compare 3 and it works well for comparing separate files, but I am at a loss for comparing single files.
Thanks in advance.
Edit:
Thanks for all the great tools! I'll definitely check them out.
This project is an ASP.NET/C# project, but I work with a variety of languages including Java; I'm interested in what tools are best (for any language) to remove duplication.
Check out Atomiq. It finds code that is duplicate that is prime for extracting to one location.
http://www.getatomiq.com/
If you're using Eclipse, you can use the copy paste detector (CPD) https://olex.openlogic.com/packages/cpd.
You don't say what language you are using, which is going to affect what tools you can use.
For Python there is CloneDigger. It also supports Java but I have not tried that. It can find code duplication both with a single file and between files, and gives you the result as a diff-like report in HTML.
See SD CloneDR, a tool for detecting copy-paste-edit code within and across multiple files. It detects exact copyies, copies that have been reformatted, and near-miss copies with different identifiers, literals, and even different seqeunces of statements.
The CloneDR handles many languages, including Java (1.4,1.5,1.6) and C# especially up to C#4.0. You can see sample clone detection reports at the website, also including one for C#.
Resharper does this automagically - it suggests when it thinks code should be extracted into a method, and will do the extraction for you
Check out PMD , once you have configured it (which is tad simple) you can run its copy paste detector to find duplicate code.
One with some Office skills can do following sequence in 1 minute:
use ordinary formatter to unify the code style, preferably without line wrapping
feed the code text into Microsoft Excel as a single column
search and replace all dual spaces with single one and do other replacements
sort column
At this point the keywords for duplicates will be already well detected. But to go further
add comparator formula to 2nd column and counter to 3rd
copy and paste values again, sort and see the most repetitive lines
There is an analysis tool, called Simian, which I haven't yet tried. Supposedly it can be run on any kind of text and point out duplicated items. It can be used via a command line interface.
Another option similar to those above, but with a different tool chain: https://www.npmjs.com/package/jscpd

Any way to rename image filenames?

Is there any way to make the "image" module store files under a new name on upload? Basically, someone could upload a file that says something like "macs are cool" or something equally absurd. Now, I don't want people to see that. I'd much rather have all the files renamed on upload to something like: "111494949478383.jpg". How would I go about accomplishing this?
The FileField Paths module should do what you want. It works with both core Upload, as well as the FileField and Imagefield modules. You may also want to check out Imagefield Tokens, which allows the use of node tokens in things like the default alt text for images.
You can use the module "filefield Paths", and put in the filename [raw] that way the uploaded picture will have the node's timestamp creation time.
Also you can use [raw]_[filename].[file-extension] or whatever combination you can use, take a look at "file name replacement patterns"
with hook_nodeapi you could move the files and rename the images when the node is saved.
Or you could add something to the image upload callback with hook form alter to rename the image once it has been uploaded
yep, form_alter is the way to go for this
there are file modules that basically use tokens to do this
edit also imagefield supports tokens http://drupal.org/node/152640
immagefield could be better in long run if cck going to Drupal 7
hope that helps

Resources