Skip to content

Instantly share code, notes, and snippets.

View vjk2005's full-sized avatar

Vijay vjk2005

View GitHub Profile
@vjk2005
vjk2005 / airmash_laser_pointer.js
Created May 5, 2018 21:41
Moz’s laser pointer extension without StarMash/SWAM dependency
function appendHtml(el, str) {
var div = document.createElement('div');
div.innerHTML = str;
while(div.children.length > 0) {
el.appendChild(div.children[0]);
}
}
var html = `
<style>
!function() {
// Fetch extension URLs and metadata
let xhttp = new XMLHttpRequest()
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
app(xhttp.responseText)
}
}
xhttp.open("GET", "https://api.jsonbin.io/b/5ada3145a8095e28cb0abcc3/12", true)
xhttp.send()
@vjk2005
vjk2005 / hn_books_bigquery.sql
Created January 20, 2018 06:26
SQL for finding all book mentions on Hacker News using Google BigQuery
SELECT
*
FROM
[bigquery-public-data:hacker_news.full]
WHERE
type="comment" AND (REGEXP_MATCH(text,r'.*amazon.*\/\d{9}.*') OR (text like '% am reading %' OR text like '% was reading %' OR text like '% just finished %' OR text like '% finished reading %' OR text like '% just read %' OR text like '% going to read %' OR text like '% about to read %'))
LIMIT
50000
@vjk2005
vjk2005 / is_empty.js
Last active January 6, 2018 02:36
Empty check for strings, arrays, objects or anything else.
const isEmpty = (obj = {}) => Object.keys(obj).length === 0
// via: https://twitter.com/peterpme/status/949352875687202816?ref_src=twcamp%5Eshare%7Ctwsrc%5Em5%7Ctwgr%5Eemail%7Ctwcon%5E7046%7Ctwterm%5E1
@vjk2005
vjk2005 / mobile_wiki_on_safari
Last active December 10, 2017 16:52
Redirect to the cleaner mobile version of Wikipedia on Safari with this JXA OS X service.
/* Put this inside a "Run JavaScript" action in Automator */
var Safari = Application('Safari'),
currentTab = Safari.windows[0].currentTab,
executionContext = {in: currentTab},
currentURL = currentTab.url(),
mobileURL = 'https://en.m.wiki' + currentURL.split("en.wiki")[1],
command = 'window.location="' + mobileURL + '"';
Safari.doJavaScript(command, executionContext)
@vjk2005
vjk2005 / dual_audio_video_to_youtube.sh
Created July 23, 2017 09:36
How to upload Japanese audio instead of English from a dual-audio video to YouTube (BONUS: convert to MP4 format as well in the same step)
ffmpeg -i <input.mkv> -map 0:0 -map 0:2 -c copy <output.mp4>
# 0:0 is the video stream to be copied as -map syntax is <input no>:<stream no>
# 0:1 is the English audio stream, skip this and map 0:2, the Japanese audio stream, to the output.
# You can see the stream info with their id by running ffmpeg -i <input.mkv>
# BONUS: convert MKV to MP4 right here with this single command
@vjk2005
vjk2005 / find_and_delete.sh
Created July 17, 2017 16:46
Find files and delete them, in this case files ending in (1).mp3 (parentheses don't need to be escaped but other brackets have to)
find * -type f -name "*(1).mp3" -delete
@vjk2005
vjk2005 / sort_folders_by_size.sh
Created July 17, 2017 16:46
sort folders in a folder by file size
du -sh */ | sort
@vjk2005
vjk2005 / file_count_folder.sh
Created July 17, 2017 16:46
count all files in a folder including sub folders
find . -type f | wc -l
@vjk2005
vjk2005 / find_total_file_size.sh
Created July 16, 2017 13:07
Find sum of a group of files in linux
du -hc <*.jpg> | tail -1
#replace <*.jpg> with the desired filter