Skip to content

Instantly share code, notes, and snippets.

@Snarp
Snarp / javascript_spoilers.html
Last active January 19, 2023 19:05
Javascript spoilers hide-and-show. Leaves spoiler text visible if Javascript isn't enabled.
<!DOCTYPE html>
<html>
<head>
<style>
.spoiler-hidden { background-color: gray; color: gray; cursor: pointer; }
</style>
</head>
<body>
<p class="spoiler">CONTENT FLAGS: Clowns, Rich People, Extended Sounds Of Brutal Pipe Murder</p>
# percent(55, 556)
# => "09.89%"
def progress_as_percentage(i, total)
"%05.2f%%" % (100.0*i/total)
end
@Snarp
Snarp / google_docs_export.rb
Created May 22, 2020 21:24
Download Google Doc as HTML (or one of various other formats)
require 'faraday'
# Valid formats: html, doc, docx, epub, odt, pdf, txt
def get_doc_as(doc_id, type='html')
Faraday.get("https://docs.google.com/document/d/#{doc_id}/export?format=#{type}").body
end
@Snarp
Snarp / generate_random_string.sh
Created May 19, 2020 17:42
Generate random string in Bash
#!/usr/bin/env bash
# How-to:
# bash rand_str.bash {{optional length}}
# Source: https://www.tldp.org/LDP/abs/html/string-manipulation.html
LEN=$1
if [ -z $LEN ]; then LEN=8; fi
@Snarp
Snarp / ai_transcript_cleanup.rb
Created April 23, 2020 00:56
Converts GDocs files in a specific format to MD
require 'nokogiri'
# (Unless you are the person I am sending this to, you do not need it.)
#
# Steps to use:
# 1. Export a Google Docs file to HTML.
# 2. Unzip the HTML file and put the filename below.
# 3. Edit css_pass (further down) to correctly convert 'c{SOME NUMBER}'-class elements to <i>, <b>, or <u>.
# 4. Run cleanup()
@Snarp
Snarp / replace_emoji.rb
Created March 28, 2020 19:47
Replaces all emoji within a string with ":#{NAME_OF_EMOJI}:"
require 'unicode/emoji'
require 'gemoji'
# Replaces all emoji within a string with ":#{NAME_OF_EMOJI}:"
# Ex: "here's a sheep emoji 🐑"
# => "here's a sheep emoji :sheep:"
def replace_emoji(str)
str.scan(Unicode::Emoji::REGEX).each do |emoji|
emoji_name = Emoji.find_by_unicode(emoji).name
puts "#{emoji} => #{emoji_name}"
@Snarp
Snarp / google-docs-copy.js
Last active May 6, 2025 16:15
Script to allow copying from a protected Google Doc
/*
<https://stackoverflow.com/questions/40296831/is-it-possible-to-force-a-copy-of-a-protected-google-doc>
NOTE - 2021-05-24
-----------------
The script below isn't the fastest way to copy-and-paste from a protected
Google Doc. Before trying it, I'd suggest following MikoFrosty's advice from
the comments:
@Snarp
Snarp / html_image_url_scraper.rb
Created April 21, 2018 20:44
Scrapes an HTML string for image URLs using Oga + regex.
require 'oga'
# Scrapes an HTML string for image URLs using Oga + regex.
class HtmlImageUrlScraper
EXTNAMES = ['.jpeg','.jpg','.gif','.png','.bmp','.svg','.tif','.tiff','.ai','.apng','.bpg','.cgm','.dxf','.eps','.flif','.hdp','.hdr','.heic','.heif','.ico','.iff','.jp2','.jpx','.jxr','.lbm','.pbm','.pgm','.pnm','.ppm','.wdp','.webp']
attr_accessor :extnames, :regexes
def initialize(extnames: EXTNAMES, regexes: nil)
@Snarp
Snarp / tumblr_client_quick_yaml_archive.rb
Created March 8, 2017 18:09
Simple Tumblr backup client using tumblr_client and saving in YAML format, created as an example.
require 'tumblr_client'
require 'fileutils'
require 'yaml'
@client = Tumblr::Client.new({
:consumer_key => "FILL",
:consumer_secret => "THESE",
:oauth_token => "FIELDS",
:oauth_token_secret => "IN"
})
@Snarp
Snarp / sinatra_tumblr_omniauth_example.rb
Created October 1, 2016 01:58
Example of how to use Omniauth to access the Tumblr API in Sinatra.
gem 'sinatra', '~> 1.4.7'
require 'sinatra'
gem 'omniauth-tumblr', '~> 1.2'
require 'omniauth-tumblr'
gem 'tumblr_client', '~> 0.8.5'
require 'tumblr_client'
require 'yaml'
# omniauth-tumblr + tumblr_client + sinatra Example