Skip to content

Instantly share code, notes, and snippets.


Niket Pathak niketpathak

View GitHub Profile
niketpathak /
Last active Mar 12, 2021
Compress Pdf in Ubuntu
# 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)
niketpathak /
Last active Feb 11, 2021
Free up a specific Port
# 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
niketpathak / generateExcerpt.php
Last active Dec 23, 2017
Generate an Excerpt from given content. Strips off html tags and preserves word boundaries
View generateExcerpt.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
niketpathak / stopwords.js
Last active Dec 21, 2017
Remove Stop words using JS
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
niketpathak / slug.js
Last active Oct 12, 2018
Generate slug using Javascript
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
niketpathak / slug.php
Last active Jul 15, 2019
Generate Slug PHP (Safe/clean urls) Original resource:
View slug.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