Skip to content

Instantly share code, notes, and snippets.

Avatar

Joshua Tzucker joshuatz

View GitHub Profile
@joshuatz
joshuatz / Android_WebView_Blocking.kt
Last active Jun 2, 2021
Example of how to intercept and block request with Android WebView
View Android_WebView_Blocking.kt
package com.joshuatz.webviewblock
import android.os.Bundle
import android.util.Log
import android.webkit.*
import androidx.appcompat.app.AppCompatActivity
// Leave off www.
val BannedDomains: Array<String> = arrayOf("facebook.com", "connect.facebook.net")
val BannedUrlPatterns: Array<Regex> = arrayOf(Regex("\\.taboola\\."))
View google-sheets-data-export-with-gas.js
/**
* @file Mini-API to export data from a Google Sheet, created for fun
* @author Joshua Tzucker
* @see https://joshuatz.com/posts/2021/google-sheets-faster-data-export-options
* @license MIT
* @see https://gist.github.com/ronaldsmartin/47f5239ab1834c47088e (alternative)
*/
// @ts-check
/// <reference path="/yarn-global/@types/google-apps-script/index.d.ts" />
@joshuatz
joshuatz / README.md
Last active Sep 9, 2020
Disable ChromeDriver messages to stdout with Selenium WebDriver & NodeJS
View README.md

Make sure you have the minimum dependencies (e.g. you have run yarn add selenium-webdriver), and edit the file with your chromedriver bin info.

Here is a full writeup

@joshuatz
joshuatz / vid_popper.js
Last active Aug 22, 2020
Video Popper for PiP - Override Disabled PiP Support
View vid_popper.js
let vidPopped = false;
document.querySelectorAll('video').forEach(vid => {
// Override disabling features
vid.removeAttribute('disablepictureinpicture');
vid.disablePictureInPicture = false;
// Only pop right away if video is playing, or on Hulu
if ((!vid.paused || vid.id === 'content-video-player') && !vidPopped) {
if (typeof vid.requestPictureInPicture === 'function') {
vid.requestPictureInPicture()
.then(() => {
@joshuatz
joshuatz / kasa.gas.js
Last active Mar 17, 2021
Google Apps Script Wrapper around Kasa API
View kasa.gas.js
/**
* @file Google Apps Script Wrapper around Kasa API
* @license MIT
* @see https://gist.github.com/joshuatz/5266d8cc85ef3e0e67561de3573a1ff5
* @author Joshua Tzucker
* @see
* - https://joshuatz.com/posts/2020/scripting-my-morning-wake-up-alarm-and-lights-with-android-and-kasa/
* - https://cheatsheets.joshuatz.com/random/tp-link-kasa/
*/
// @ts-check
@joshuatz
joshuatz / AndroidManifest.xml
Created Jan 4, 2020
TP-Link Kasa Android Manifest
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="29" android:compileSdkVersionCodename="10" package="com.tplink.kasa_android" platformBuildVersionCode="900" platformBuildVersionName="2.18.0.900">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
@joshuatz
joshuatz / PowerBI_JS_API_Reset_All_Slicers_Filters.js
Created May 17, 2019
Reset all Slicers (visual filter widgets) within a Power BI Javascript Embed
View PowerBI_JS_API_Reset_All_Slicers_Filters.js
async function resetAllSlicers() {
// This will target first embed on page, you can easily change
let report = powerbi.embeds[0];
let pages = await report.getPages();
for (let x = 0; x < pages.length; x++) {
let visuals = await pages[x].getVisuals();
for (let x = 0; x < visuals.length; x++) {
if (visuals[x].type === 'slicer') {
// Clear state, but wait before moving on to next one, since clearing a filter can have a cascade effect
try {
@joshuatz
joshuatz / node_file_downloader.js
Created May 12, 2019
File downloader that you can call with Node and pass a URL, that has options for checking file integrity after download
View node_file_downloader.js
/**
* @author Joshua Tzucker
* @file A reusable script to download a remote file, usually to have as a dependency, that for some reason can't be fetched through NPM
*/
/**
* File should be called with arguments:
* file_downloader.js remote_file local_folder_to_save_to [newFileName="foobar.js"][forceReDownload=FALSE] [fileHash="sha256-adsfasfd"]
* fileHash should be base64 - follow rule of SRI - https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
* Example:
@joshuatz
joshuatz / restart_dropbox.bat
Created May 11, 2019
Restart the Dropbox client by running a Windows Batch Script. Searches in both Program Files directories for exe to start back up.
View restart_dropbox.bat
@echo off
cls
REM # Find and kill the dropbox process
taskkill /FI "IMAGENAME eq Dropbox.exe" /F
REM # Wait a little
@echo on
cls
echo "Please wait while restarting Dropbox"
@echo off
SLEEP 5
View Employee-Conditional-Tag-Loading.js
(function(){
function httpFetchVanilla(url,method,callback,OPT_failCallback){method="string"==typeof method&&""!==method?method:"GET",callback="function"==typeof callback?callback:function(){},failCallback="function"==typeof OPT_failCallback?OPT_failCallback:function(){console.warn("httpFetchVanilla failed")};var t=new XMLHttpRequest;t.onreadystatechange=function(){4==t.readyState&&(200==t.status?callback(t.responseText):failCallback())},t.open(method,url,!0),t.send()}
function setCookie(name, value, days) {
var d = new Date;
d.setTime(d.getTime() + 24*60*60*1000*days);
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
}