Skip to content

Instantly share code, notes, and snippets.

View thermistor's full-sized avatar
🏠
Working from home

Weston Triemstra thermistor

🏠
Working from home
View GitHub Profile
@thermistor
thermistor / request_helpers.rb
Created October 12, 2023 22:16 — forked from dogweather/request_helpers.rb
Use CSS Selectors in RSpec Request Specs
def css(selector)
html.css(selector).text
end
def html
Nokogiri::HTML(response.body)
end
@thermistor
thermistor / .rubocop.yml
Created January 27, 2022 07:29 — forked from gavvvr/.rubocop.yml
Rubocop IDE linting using/overriding standardrb rules
require:
- standard
- rubocop-rspec
inherit_gem:
# First check this: https://github.com/testdouble/standard#how-do-i-run-standard-in-my-editor
# If your editor invokes 'rubocop' directly and knows nothing about 'standard' gem,
# it can be useful to inherit 'standard' set of rules
standard: config/base.yml
@thermistor
thermistor / application.rb
Created June 4, 2021 01:48 — forked from averyvery/application.rb
Inline CSS or JS in Rails
config.assets.precompile += [
# precompile any CSS or JS file that doesn't start with _
/(^inline[^_\/]|\/[^_])[^\/]*.(js|css)$/,
...
@thermistor
thermistor / nmap-rspec.rb
Created July 20, 2020 18:27 — forked from garethr/nmap-rspec.rb
Example nmap scan of the monitorama.eu website written as an rspec test
tarting Nmap 6.40 ( http://nmap.org ) at 2013-11-15 09:36 GMT
Nmap scan report for monitorama.eu (141.101.116.49)
Host is up (0.012s latency).
Other addresses for monitorama.eu (not scanned): 141.101.117.49
PORT STATE SERVICE
20/tcp filtered ftp-data
21/tcp filtered ftp
22/tcp filtered ssh
23/tcp filtered telnet
25/tcp filtered smtp
@thermistor
thermistor / oneliners.js
Last active April 1, 2019 16:43 — forked from mikowl/oneliners.js
👑 Awesome one-liners you might find useful while coding.
// By @coderitual
// https://twitter.com/coderitual/status/1112297299307384833
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// Type this in your code to break chrome debugger in that line.
require 'resolv'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if Resolv::DNS.new.getresources(value.split("@").last, Resolv::DNS::Resource::IN::MX).empty?
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
rescue Resolv::ResolvError, Resolv::ResolvTimeout
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
@thermistor
thermistor / trrprefs.md
Created September 26, 2018 06:35 — forked from bagder/trrprefs.md
trr prefs

Preferences

All preferences for the DNS-over-HTTPS functionality in Firefox are located under the "network.trr" prefix (TRR == Trusted Recursive Resolver). The support for these are targeted for shipping in release Firefox 62.

network.trr.mode

set which resolver mode you want.

0 - Off (default). use standard native resolving only (don't use TRR at all)

1 - Race native against TRR. Do them both in parallel and go with the one that returns a result first.

@thermistor
thermistor / lang.map.diff
Last active July 28, 2018 21:30 — forked from tkfm-yamaguchi/lang.map.diff
source-highlight's language definition file for YAML
---/usr/share/source-highlight/lang.map.old
+++/usr/share/source-highlight/lang.map
@@ -169,3 +169,5 @@
groovy = groovy.lang
json = json.lang
feature = feature.lang
+yaml = yaml.lang
+yml = yaml.lang
@thermistor
thermistor / 1-activerecord.rb
Created March 14, 2018 17:38 — forked from janko/1-activerecord.rb
INSERTing 50,000 records into a database in ActiveRecord, Arel, SQL, activerecord-import and Sequel.
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Migration.class_eval do
create_table(:records) do |t|
t.string :column
end
end
data = 50_000.times.map { |i| Hash[column: "Column #{i}"] }
@thermistor
thermistor / bulk_insert.rb
Created March 14, 2018 17:38 — forked from maxjustus/bulk_insert.rb
Simple SQL bulk insert in Rails
# Takes a table name, and an array of hashes where keys are column names and values are values.
# Expects hashes to all contain the same keys.
def bulk_insert(table, rows)
columns = rows.first.keys
to_insert = rows.map do |d|
vals = columns.map {|k| d[k] }
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals)
end