Skip to content

Instantly share code, notes, and snippets.

@Snarp
Snarp / initialize_watir_firefox_with_profile.rb
Last active September 8, 2021 18:15
Initializes an instance of Watir::Browser using a specified Firefox profile.
require 'watir'
require 'webdrivers/geckodriver'
# Source:
# <https://github.com/SeleniumHQ/selenium/issues/7796#issuecomment-555833317>
# Find your Firefox profile's directory by opening 'about:support' in the
# browser and scrolling down to the 'Profile Directory' field.
#
# Alternately, to create a new profile, go to 'about:profiles' and click
@Snarp
Snarp / init_watir_edgedriver_on_ubuntu.rb
Created June 24, 2021 01:24
Initialize a Microsoft Edge Watir/Selenium browser/driver on Ubuntu 18.04
# NOTE: The Edge version in use here is:
# `92.0.902.15 (Official build) beta (64-bit)`
gem 'selenium-webdriver', '=4.0.0.beta4'
require 'selenium-webdriver'
gem 'watir', '~> 6.19'
require 'watir'
# gem 'webdrivers', '~> 4.6' # Edge not supported on Linux as of latest release
# require 'webdrivers'
@Snarp
Snarp / mute_etsy_ads_userscript.js
Created April 28, 2021 22:48
Etsy.com - Mute Deceptive Search Result Ads: Hides the difficult-to-identify ads in Etsy search results.
// ==UserScript==
// @name Etsy.com - Mute Deceptive Search Result Ads
// @author snarp
// @version 0.3
// @description Hides the difficult-to-identify ads in Etsy search results.
// @run-at document-idle
// @include https://www.etsy.com/*/search?q=*
// @include https://www.etsy.com/search?q=*
// @grant none
// @icon https://www.etsy.com/images/favicon.ico
@Snarp
Snarp / 00-README.md
Created January 17, 2021 20:59 — forked from nightpool/00-README.md
NPF-to-HTML renderer

npf.js is the main bulk of the code, and it exposes three functions:

renderContent

Render content returns an object {content, ask}. It returns the ask content separately so it can be handled spearately by the consuming client. content is an HTML element, ask is itself an object containing content (an HTML element) and the other properties of the ask layout type (specifically of interest is the attribution property).

mentions

media

@Snarp
Snarp / radkfile.yml
Created November 12, 2020 23:26
Kanji radicals associated with lists of kanji that include them, converted to UTF-8 YAML from http://ftp.monash.edu.au/pub/nihongo/radkfile.gz
---
一: 亜唖阿姶悪芦或袷夷椅畏異遺井郁一芋蔭陰右窺丑云雲盈益榎円延援演塩汚央岡下何可夏寡歌河珂苛荷華嘩画悔開碍垣劃隔岳橿恰且樺釜栢萱瓦乾寒干桓漢環看緩還関含基奇寄希棄稀貴輝騎儀宜犠義蟻誼議丘朽求給虚亨供共彊興尭業極桐僅勤琴衿吟倶駈具勲君薫群郡刑啓型形恵慧荊倹兼券喧圏拳捲研肩遣乎戸雇顧互碁乞光后宏巧恒晃更梗構洪溝硬紘綱肱講購閤号合今佐左査再最塞妻才犀在材財肴咲崎埼碕作柵冊三参惨珊蚕伺使司嗣屍師施死至詞事慈滋爾璽磁雫写斜遮若惹寿拾重春所叙序徐除傷症称証象鉦上丈丞乗剰場擾杖畳蒸飾慎晋榛真秦甚笥垂睡衰錘随髄世征政整正席惜昔籍宣扇煎煽箭前岨措狙疎祖租粗組阻創倉喪奏爽曹槍槽漕争糟葬蒼送遭鎗像束速袖其揃存唾堕惰楕体帯戴泰宅托託諾但巽丹嘆坦担旦歎湛胆壇断暖檀段値置窒昼苧貯丁庁暢町腸頂勅直朕鎮陳槻椿潰壷低停汀訂釘鼎迭典天展添殿澱塗途砺度凍唐塔塘搭東棟湯灯答筒董蕩藤謄騰働動同洞胴銅峠得凸寅乍弐廿禰寧年念捻乃嚢濃膿農覗廃拝杯盃曝爆函肇鉢髪蛤挽否扉畢逼紐百評病蛭浜賓瓶不富冨布怖普譜撫舞蕪副復幅福腹淵糞丙併兵塀柄並閉偏篇編遍便鞭俸奉峰峯捧縫蓬蜂豊鋒房暴棒奔本鮪柾俣抹末万満湊蓑稔無命免餅戻矢鑓愉愈諭輸佑優友宥憂有祐郵雄予余与誉預揚楊陽翼欄蘭吏了両糧量領倫臨輪涙令伶冷嶺怜玲苓鈴零霊麗齢煉錬炉婁蝋論歪賄亙亘弌丐丕亊亞亳亶仗佇佩佰侑來侖倚會偈偸僉僵儉兀兩兪册冉冓冱剏剄剞剪剳劍劔劒匐匱匳卅卍厦叮咀哄哈哥唏哽唸唳喘喩嗄嘸嚥囂囹囿圜圷坏垪堊堙塲墟壙壤壺壼壽竒妲妍娉婀媾嫣孃孳孺實寰專尹屏岑妛岻峇峺崋嵜崙崘嶮巵帶并廈廡廳弖彁彌徑忸忝恠怎怛恆恫惡惠愃愴慯慝憙憮懣戛戞扁拔抔拿拱拵掎掵捩揄搴搆搶擅舉攀敍敘數斂昊昜晉晞晝暄暘曁曄曩朞朮朿杤枦枅柯檜桎栫梹梺椏棊棗棯椪椣棆楡寨樓橢檢櫃檸欷欹歛歟殤氈沍洽浤涵淆淒淪湲湎滿渝滄滬滯澑澪濔瀑瀰瀲炳烝焉煖煬爨爰犲狃猗獪獸璢瑜瑾瓸甦甼畫畭畸疆畴疔疸痞痾瘍瘉瘡瘻癸盒盪蘯盻眄瞞瞶瞼矗矜碣祠祗祓禪禮禳秉秡秣稱穰窘窶竡笨笄箚篝簑簔篳簍篶簣簽籥粐粤粭粡粨粳鬻絨絣綺綮綸綟緻縣縉縷繖繪罔罘羚羶翕翦翩聆聘胚隋腆胼膓膾膸臉與艙艚舮苒苴莓茉荐荅莟莖茣荼萓菫蒹蓆蓴蔗蔕蕘薈薑藪藉乕號虱蚩蚌蚯蛉蛬蜍蝨蝙蝓蝪螻蠹衄衙衾袒裲褄褊襄褸覦覯觴訶諠諞謌謇諡譁譴讌讓豺貪賚賽跚跋踰蹇蹌蹠蹣蹕軆輊輌輳辷邇逕迸逾遘隨邱扈酊醋醢醴釀鈕錏鍮鎭鏤鈩鑰閂閧陏陲險霰靼鞳頷顫颪餘饉饋騁駢騙騫驗髏髓髯鬟鯑鯰鱠鴒鴿鵲鷓黔黻齡龕龠堯槇
|: 亜唖逢悪以伊遺井稲印引鵜丑渦円焔艶押横沖下果
@Snarp
Snarp / kradfile.yml
Created November 12, 2020 23:07
Kanji radical index converted to UTF-8 YAML from <http://ftp.monash.edu.au/pub/nihongo/kradfile.gz>
---
亜: [|,一,口]
唖: [|,一,口]
娃: [女,土]
阿: [一,口,亅,阡]
哀: [衣,口,亠]
愛: [心,爪,冖,夂]
挨: [矢,厶,扎,乞]
姶: [一,口,女,个]
逢: [|,込,二,夂]
@Snarp
Snarp / scrape_google_drive_folder_contents.rb
Created October 27, 2020 00:18
Given a Google Drive folder URL, attempts to extract a list of Google Doc names and IDs.
require 'yaml'
require 'faraday'
require 'nokogiri'
# REVIEW: May not work for directories with larger numbers of files.
# REVIEW: Formatting will likely be different for non-Google-Docs files.
# REVIEW: This is stupid.
def scrape_folder_contents(gdrive_folder_url, output_fname=nil)
html = Faraday.get(gdrive_folder_url).body
doc = Nokogiri::HTML(html)
# This isn't the official Ruby Tumblr client, it's a clone that accepts some extra arguments
require_relative 'lib/tumblr_client'
@credentials = YAML::load(File.read('credentials.env.yml'))
@client ||= TumblrClient.new(**@credentials)
@info ||= @client.user_info[:user]
@uuid ||= @info[:blogs].first[:uuid]
@username ||= @info[:name]
@Snarp
Snarp / is_integer.rb
Created June 24, 2020 19:10
Checks whether a value is an integer, should work in Ruby 2.6 and above. (Relies on `Float()` permitting `exception: false`)
# Checks whether a value is an integer, should work in Ruby 2.6 and above.
# (Relies on `Float()` permitting `exception: false`:
# <https://rubyreferences.github.io/rubychanges/2.6.html#numeric-methods-have-exception-argument>)
def is_integer?(val)
flt = Float(val, exception: false)
return flt && flt.to_i==flt
end
def is_number?(val)
return !!Float(val, exception: false)
@Snarp
Snarp / extract_youtube_closed_captions.rb
Created June 14, 2020 14:43
Extracts all UTF-8 strings from YouTube's closed caption ("timedtext") JSON object to generate a rough transcript.
require 'json'
# Extracts all UTF-8 strings from YouTube's closed caption (`timedtext`) JSON
# object to generate a rough transcript.
#
# Instructions for acquiring the JSON:
#
# 1. Open the video in a new Firefox tab. Don't click "CC" yet.
#
# 2. Open Firefox Developer Tools (right-click somewhere and select "Inspect