View reduce-pdf-size.sh
# Use the following ghostscript command: | |
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \ | |
-dNOPAUSE -dQUIET -dBATCH -sOutputFile=/home/niketpathak/Downloads/output.pdf /home/niketpathak/Downloads/input.pdf | |
# Summary of -dPDFSETTINGS: | |
# -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi) | |
# -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi) | |
# -dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi) | |
# -dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi) |
View free-up-port.sh
# Get the process ID of the process running on port xyz | |
lsof -i -P -n | grep xyz # xyz is the desired port number | |
# Force kill the process running on the port by providing the process ID you find from the above statement | |
kill -9 processID | |
#### More info on lsof #### | |
# lsof => list open files | |
# -i => selects IPv[46] files | |
# -P => No port names |
View generateExcerpt.php
<?php | |
echo generateExcerpt('Some long text is not really present here', 15); // Some long... | |
/** | |
* Generate an Excerpt for a given String | |
* @param string $content The content | |
* @param int $maxLength The maximum length of the desired excerpt | |
* @param string $more the string to use as more | |
* @return string | |
*/ |
View stopwords.js
/** | |
* Strip off Stopwords from a given string | |
* @param inputString The input string | |
* @param stopWords {optional} An array of stopwords | |
* @returns {string} | |
*/ | |
function removeStopWords (inputString, stopWords) { | |
if (!!inputString) return ''; | |
if (!!stopWords || (stopWords && stopWords.constructor !== Array)) { | |
stopWords = [ "a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "could", "did", "do", "does", "doing", "down", "during", "each", "few", "for", "from", "further", "had", "has", "have", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "it", "it's", "its", "itself", "let's", "me", "more", "most", "my", "myself", "nor", "of", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "ow |
View slug.js
/** | |
* Generate a slug | |
* @param inputString The input String | |
* @returns {string} | |
*/ | |
function slugify(inputString) { | |
return inputString.toString().toLowerCase().trim() | |
.replace(/&/g, '-and-') // Replace & with 'and' | |
.replace(/[\s\W-]+/g, '-') // Replace spaces, non-word characters and multiple-dashes with a single dash (-) | |
.replace(/(^-|-$)/g, '') // Remove dangling hypens in case slug begins or ends with a special character |
View slug.php
<?php | |
echo slugify('Hello World///&?Welcome'); // hello-world-welcome | |
/** | |
* Generates a slug from the given string | |
* @param $input The input string | |
* @param string $replacement The character/string to use as the replacement value | |
* @return mixed|string | |
*/ |