Skip to content

Instantly share code, notes, and snippets.

View niketpathak's full-sized avatar
🦸

Niket Pathak niketpathak

🦸
View GitHub Profile
@niketpathak
niketpathak / free-up-port.sh
Last active September 16, 2021 10:33
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
# if you have npm/npx
npx kill-port portNumber
#### More info on lsof ####
@niketpathak
niketpathak / reduce-pdf-size.sh
Last active March 12, 2021 13:04
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
niketpathak / slug.php
Last active July 15, 2019 13:38
Generate Slug PHP (Safe/clean urls) Original resource: https://stackoverflow.com/a/2955878/4717533
<?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
*/
@niketpathak
niketpathak / slug.js
Last active October 12, 2018 16:21
Generate slug using Javascript
/**
* 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
niketpathak / generateExcerpt.php
Last active December 23, 2017 23:38
Generate an Excerpt from given content. Strips off html tags and preserves word boundaries
<?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
niketpathak / stopwords.js
Last active December 21, 2017 15:10
Remove Stop words using 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