Skip to content

Instantly share code, notes, and snippets.

@ttilberg
ttilberg / readme.md
Last active August 4, 2023 15:02
My MiniTest + VCR `with_vcr {}` selective recording configuration

Minitest Recordable

This small module sets up VCR in a way that makes using VCR in Minitest a breeze. You can wrap specific parts of your test in a with_vcr block that will automatically create and name a cassette and directory based on the test and class name, and handles nested names. It works great both from inside Rails, and not.

The example test file in this gist stores its results to test/vcr/Search_GoogleTest/test_search.yml.

@ttilberg
ttilberg / debug_runner.py
Last active September 9, 2020 20:51
Scrapy debugging in VSCode made easy.
from scrapy.cmdline import execute
try:
execute(
[
'scrapy',
'crawl',
'spidername',
# '-a',
# 'some_attr=some_value
require "nokogiri"
# A base class for page objects.
# It works similar to SimpleDelegator, but parses incoming text if not done already.
# Any methods not explicitly defined are delegated to the underlying Nokogiri object.
#
# Example:
#
# class SearchPage < DocWrapper
# def results
require 'kiba'
require 'awesome_print'
class ExampleSource
def each
(1..10).each do |i|
yield ({
index: i
})
end
# Some various moves
defaults write com.apple.screencapture location ~/Downloads && killall SystemUIServer
echo "alias clip=pbcopy
alias ls='ls -G'
alias ll='ls -alG'
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
" >> ~/.bash_profile
@ttilberg
ttilberg / config_initializers_geocoder.rb
Last active April 27, 2018 16:17
Geocoder SQL Server bearing support
# Rewritten bearing function that supports SQL Server:
# - ATAN2 function renamed ATN2
# - Use `%` operator instead of `MOD()` function
# This seems like it would be very reasonable to apply more dynamically.
#
# Original source: https://github.com/alexreisner/geocoder/blob/317832ca2b7ec234fca6039184686d921bac925d/lib/geocoder/sql.rb#L57
#
module Geocoder
module Sql
##
@ttilberg
ttilberg / converter.rb
Last active July 5, 2023 08:24
Utilities to unobfuscate a certain class of js files.
require 'net/http'
require 'json'
require 'uri'
require 'yaml'
##
# Make a certain obfuscated js less obnoxious to analyze.
#
class Obfuscated
attr_accessor :script
@ttilberg
ttilberg / has_required_properties_test.rb
Created August 18, 2015 19:22
Test if @properties are set and not empty
require 'pry'
class Thing
REQUIRED = [:a,:b,:c]
attr_accessor :a, :b, :c, :d
def initialize( a: '', b: '', c: '', d: '')
@a = a.to_s
@b = b.to_s