shell script to check if images in a folder are being used by a set of HTML files - linux

Sometime ago I worked in a team that developed a bunch of educational softwares and now they are been reviewed for bugs and updates.
During this process, I noticed that the folder "imgs" accumulated too many files. Probably one of the developers decided to include all the images used by each of the softwares into the folder. However, because there are too many softwares, it would be too painful to check manually all of them (and some of the images are part of the layout, almost invisible).
Is there a way to write a shell script in Linux to check if the files in a given folder are being used by a set of HTML and JS files in another folder?

Go to the images folder and try this
for name in *; { grep -ril $name /path/to/soft/* || echo "$name not used"; }

Im not sure I understood your question correctly,
But maybe this will help you
ls -1 your_source_path | while read file
do
grep -wnr "$file*" your_destination_path ||
echo "no matching for file $file"
# you can set any extra action here
done
in source_path you put director from hi will list all files name and destination where he should searching.

It is not possible to check for the generic case - since HTML and Javascript are two dynamic (e.g. the Javascript code could create the image file name on the file). Likewise, images can be specified in CSS style sheet, inline style, etc.
You want to review the HTML/JS files, and see if possible to identify the tags that are actually used to specify images. This will hopefully, reduce the number of XML tags and attribute names that need to be extracted.
As an alternative, if you have access to the 'access log' of the server, you can find out which images have been accessed over time, and focus the search on images not referenced in the log file.

Related

Delete folder by name from google drive using gdrive

I have read the documentation for gdrive here, but I couldn't find a way to do what I want to do. I want to write a bash script to upload automatically a specific folder from my hard drive. The problem is that when I upload it several times, instead of replacing the old folder by the new one, it generates a new folder with the same name.
I could only find the following partial solutions to my problem:
Use update to replace files. The problem with this partial solution is that new files inside the folder could not get uploaded automatically, and I would have to change the bash script every time a new file is produced in the folder that I want to upload.
Erase the folder by its id from google drive and then upload the folder again. The problem here is that whenever I do this, the id of the uploaded folder chagnes, so I couldn't find a way to write a script to do the work.
I am looking for any method that solves my problem. But the precise questions that could help me are:
Is there a way to delete a folder from google drive (using gdrive) by its name instead of by its id?
Is there a way to get the id of a folder by its name? I guess not, since there can be several folders with the same name (but different ids) uploaded. Or am I missing something?
Is there a way to do a recursive update to renew all files that are already inside the folder uploaded on google drive and in addition upload those that are not yet uploaded?
In case it is relevant, I am using Linux Mint 18.1.
Is there a way to delete a folder from google drive (using gdrive) by its name instead of by its id?
Nope. As your next question observes, there can be multiple such folders.
Is there a way to get the id of a folder by its name? I guess not, since there can be several folders with the same name (but different ids) uploaded. Or am I missing something?
You can get the ids (plural) of all folders with a given name.
gdrive list -q "name = 'My folder name' and mimeType='application/vnd.google-apps.folder' and trashed=false"
Is there a way to do a recursive update to renew all files that are already inside the folder uploaded on google drive and in addition upload those that are not yet uploaded?
Yes, but obviously not with a single command. You'll need to write a short script using gdrive list and parse (awk works well) the output.

How do I serve MathJax from a local Happstack server?

I'm not a developer/programmer. I'm just someone trying to use Gitit to take notes. I've got it to the point where it runs on Windows, but the math looks best using MathJax. I don't want to rely on a remote CDN to get the MathJax working (power cuts and internet disconnections are very frequent here). The author of the app mentions it can be setup in "4 lines of code" in Happstack:
mathjax-script: https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
# specifies the path to MathJax rendering script.
# You might want to use your own MathJax script to render formulas without
# Internet connection or if you want to use some special LaTeX packages.
# Note: path specified there cannot be an absolute path to a script on your hdd,
# instead you should run your (local if you wish) HTTP server which will
# serve the MathJax.js script. You can easily (in four lines of code) serve
# MathJax.js using http://happstack.com/docs/crashcourse/FileServing.html
# Do not forget the "http://" prefix (e.g. http://localhost:1234/MathJax.js)
The link to the tutorial is broken, so I'd be grateful for some assistance. Is there is any MathJax configuration I need to change, or simply extracting the files will do? I'll be writing lots of math in gitit. I'd prefer not to set up Apache etc. to serve MathJax. Gitit already uses Happstack, I'd prefer using that. Thanks!
EDIT: Just to be clear I'm not sure how to assign the port 1234 to serve this script
Ok I got MathJax working using portable Apache and the MathJax archive downloaded from docs.mathjax.org. The URL needs to be of the form (assuming you extracted the files into apache2/htdocs/MathJax):
http://localhost/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML
I wanted to keep this lightweight by reusing the same instance of Happstack as Gitit, but that seems beyond my skills/available time right now.
EDIT: Just found out that ghc will pack everything into one exe when building. So I doubt it is even possible to use the same Happstack instance, as the root directory of the server doesn't exist?
From the documentation, the static directory should work just fine:
On receiving a request, gitit always looks first in the static
directory (or in whatever directory is specified for static-dir in the
configuration file). If a file corresponding to the request is found
there, it is served immediately. If the file is not found in static,
gitit next looks in the static subdirectory of gitit's data file
($CABALDIR/share/gitit-x.y.z/data). This is where default css, images,
and javascripts are stored. If the file is not found there either,
gitit treats the request as a request for a wiki page or wiki command.
So, you can throw anything you want to be served statically (for
example, a robots.txt file or favicon.ico) in the static directory.
You can override any of gitit's default css, javascript, or image
files by putting a file with the same relative path in static. Note
that gitit has a default robots.txt file that excludes all URLs
beginning with /_.
(source: https://github.com/jgm/gitit)
Download the MathJax.js file from e.g. cdn.mathjax.org and place it in data/static/js/MathJax.js. Then change the config you quote to:
mathjax-script: http://localhost:5001/js/MathJax.js

SUSY organization files?

I use method mobile first or a reponive webite and i use susy. How organize files _forms _typo _layout,_mixins etc.. for mobile (default) and breakpoints (tablet, desktop) and to have output files :
mobile.css
tablet.css
desktop.css
Thanks
Sass/Compass+Susy will create a file for every file in your source directory that is not preceded by an underscore.
So, simply place the code you want generated for those style sheets in files located in the source directory using any mixins from your own partials (files preceded by an underscore) or any of the extensions you're including on your project (such as susy)
A great document that talks about structuring your project is here: http://compass-style.org/help/tutorials/extensions/
Something else to look at: http://compass-style.org/help/tutorials/best_practices/
Great
i understand the technics with '_' files not generated but i search sample organization iles or responive website with susy .
if i use multiple files for layout header etc... (include or each at-breakpoint) the css file result contains miltiple declaration #media.... and not grouped .

How to use .htaccess to reformat a directory listing while including the directory name?

For directory listings, I've created a common .htaccess file as well as a common header ("HeaderName /header.html).
Everything works fine, except one thing: while I don't want the derpy h1 version of "Index of /blah", I'd like to display a customized (and normal-sized) version of that, e.g., "CurDir = /blah". By default, specifying the HeaderName replaces all of that with some static text.
I tried embedding a bit of PHP (getcwd()) but that just returned the root directory where the header.html lives, no matter what subtree was being displayed. Surely there's some way to access the CWD without having to sprinkle control files like this in each subfolder?
I stumbled upon what may be a suitable environment variable while looking at the phpinfo() output... but is there a better (more common) way people handle this, perhaps without even using PHP?
<?php
$dir = getenv("REQUEST_URI");
?>

Using htaccess to bundle a bunch of files into a single one

Say you have a css files loader style.php:
<?php
header('Content-type: text/css');
foreach(array('style1.css', 'style2.css', 'style3.css') as $f)
echo file_get_contents($f)
?>
Style1.css has 12KB, style2.css is 400kgs, and in the red corner obese style3.css weighting 800LBs is world champion at static resource bandwidth consumption!
I'm using style.php to combine the three files and send them to the client. I'm also using similar php files to send out JS resources, combined.
Is there some htaccess rule that I can tell to combine several static resources into a big one, and send that on-the-fly?
/EDIT:
This type of job CAN be handled by htaccess I'm sure I've read somewhere about server files included or something like that but I don't remember where. And I've also seen free hosting services that put a custom header or banner regardless of what files you host there.
Well this type of job (combining css files) cannot be handled by .htaccess. You can at best use mod_deflate to compress the css file's contents.
However in PHP code you can combine and compress various CSS files. Take a look at third method in http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php
Finally take a look at minify here: http://www.minifycss.com/minify-tools/minify-css-tools.php
Eventually found what I was looking for. The thing was called Server-Side Includes (SSI).

Resources