Skip to content

Instantly share code, notes, and snippets.

View HR's full-sized avatar

Habib Rehman HR

View GitHub Profile
@HR
HR / screen.sh
Created May 21, 2021 18:21
Restore screen session if exist or start new one ssh
# Connect to screen session
case "/$(ps -p $PPID -o comm=)" in
*/sshd) screen -RR;;
esac
@HR
HR / download.js
Created March 12, 2021 15:16
Deno CLI to download JSON links to directory
import { download, Destination } from 'https://deno.land/x/download/mod.ts'
function error(msg) {
console.error(msg)
Deno.exit(1)
}
/**
* @param file The JSON file path
* @param path The JSON object path
* @param dest The download destination dir (optional, defaults to current)
@HR
HR / getFolderByName.js
Created November 24, 2020 18:41
Google Drive v3 API NodeJs get folder by name if exists or create a new one otherwise
let folderId
const parentFolderId = ''
const folderName = ''
// Check if folder already exists
const folderSearch = await drive.files.list({
q: `mimeType = 'application/vnd.google-apps.folder' and name = '${folderName}' and '${parentFolderId}' in parents`,
fields: 'nextPageToken, files(id, name)',
spaces: 'drive'
})
@HR
HR / amzninvoicedownload.js
Created November 15, 2020 15:14
Amazon Invoice download
var sleepInterval = 2200;
var sleep = 0;
function finda(txt) {
let finds = Array.from(document.querySelectorAll('a'))
.filter(el => el.textContent.includes(txt))
console.log(txt + ': ' + finds.length)
return finds
}
@HR
HR / util.sh
Created June 4, 2017 11:29
Useful bash utility functions
# FileSearch
function f() { find . -iname "*$1*" ${@:2} }
# File removal by name
function frm() { find . -iname "*$1*" -print0 | xargs -0 rm -r }
# File content search
function fr() { grep "$1" ${@:2} -R . }
# mkdir and cd
@HR
HR / closeLinkSafari.scpt
Created December 31, 2016 18:47
Close tabs containing a URL in Safari Applescript
on run argv
set passedInURL to (item 1 of argv)
tell application "Safari"
set windowCount to number of windows
repeat with x from 1 to windowCount
set tabCount to number of tabs in window x
repeat with y from 1 to tabCount
set thistab to tab y of window x
set thisURL to URL of thistab
if passedInURL is in thisURL then close thistab
@HR
HR / running.sh
Created May 16, 2016 16:40
Check if processes are running bash
#!/bin/bash
for proc in "$@"
do
RUNNING=$(pgrep $proc)
if [[ $RUNNING ]]
then
# do stuff if running
echo "$proc is running"
else
@HR
HR / SelectMenubarItemGUI.scpt
Created May 16, 2016 16:15
Select Menubar Item Applescript (for GUI)
on run argv
set procName to (item 1 of argv)
set menuItem to (item 2 of argv)
ignoring application responses
tell application "System Events" to tell process procName
tell menu bar item 1 of menu bar 1
click
end tell
end tell
end ignoring
@HR
HR / npm-update-latest.sh
Last active March 30, 2018 21:46
NPM update all global packages to latest version
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f2 | sed 's/@.*//g')
do
npm -g install "$package@latest"
done
@HR
HR / openLink.scpt
Created April 24, 2016 12:51
Open new tab with URL (in the background) in Chrome Applescript