Skip to content

Instantly share code, notes, and snippets.

@Snarp
Snarp / sinatra_tumblr_oauth_example.rb
Last active April 2, 2016 04:04
Example of how to use OAuth to access the Tumblr API in Sinatra.
gem 'sinatra', '~> 1.4.7'
require 'sinatra'
gem 'oauth', '~> 0.5.1'
require 'oauth'
gem 'tumblr_client', '~> 0.8.5'
require 'tumblr_client'
# This is an example of how to use OAuth to access the Tumblr API in Sinatra.
# Based on dcesteri's Twitter example:
# https://github.com/dcestari/sinatra-twitter-oauth-sample
@Snarp
Snarp / keypress_toggle_writer.au3
Created May 11, 2016 20:13
AutoIt script which types one line from Kafka's Metamorphosis and then presses enter every 3 seconds; toggle-able using Pause/Break.
#include <FileConstants.au3>
; Pause/Break to "turn on" and "turn off".
; While turned on, writes one line from the text file defined by $FILENAME and then presses "Enter" every $SLEEPFOR millseconds.
; Defaults = Kafka's Metamorphosis, 3 seconds.
;
; If you have never needed to do this, don't worry about it. Just don't worry about it.
Global Const $FILENAME = "metamorphosis.txt"
Global Const $SLEEPFOR = 3000
@Snarp
Snarp / watir_firefox_mobile_example.rb
Created May 18, 2016 19:22
Working example of how to load the mobile version of a site using watir-webdriver 0.9.1, selenium-webdriver 2.53.0, webdriver-user-agent 7.4, and Firefox 46.0.1. (Version numbers important because Firefox.)
require 'watir-webdriver'
require 'webdriver-user-agent'
# Works as of:
# - watir-webdriver 0.9.1
# - webdriver-user-agent 7.4
# - selenium-webdriver 2.53.0
# - Firefox 46.0.1
# Creates new Firefox profile to bypass Firefox's chronic profile glitches.
@Snarp
Snarp / tungle_client.rb
Created July 20, 2016 09:29
Ruby module for backing up/archiving public Tumblr data.
require 'typhoeus'
require 'json'
module TungleClient
EXAMPLE_API_KEY = 'fuiKNFp9vQFvjLNvx4sUwti4Yb5yGutBN4Xh10LXZhhRKjWlV4'
BASE_BLOG_URL = 'https://api.tumblr.com/v2/blog'
BASE_TAG_URL = 'https://api.tumblr.com/v2/tagged'
# NOTE: ssl_verifypeer is turned off here due to eternal font of Windows
@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
@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 / 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 / google-docs-copy.js
Last active May 26, 2024 04:12
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 / 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 / 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()