Skip to content

Instantly share code, notes, and snippets.

@just3ws
just3ws / convert_string_hash_representation_to_ruby_hash.rb
Last active December 12, 2023 01:27
Converting a string representation of a Ruby Hash back into a Ruby Hash
require 'pp'
require 'json'
s = "{:exit_url=>\"null\", :exit_target_type=>\"left\", :furthest_scrolled=>\"locations\", :time_spent=>\"543210\", :user_id=>\"123456\", :visited_at=>789101112, :user=>nil}"
pp JSON.parse("{" + s.gsub(/^{|}$/, '').split(', ').map { |pair| pair.split('=>') }.map {|k, v| [k.gsub(/^:(\w*)/, '"\1"'), v == 'nil' ? "null" : v].join(": ") }.join(", ") + "}")
=> {"exit_url"=>"null", "exit_target_type"=>"left", "furthest_scrolled"=>"locations", "time_spent"=>"543210", "user_id"=>"123456", "visited_at"=>789101112, "user"=>nil}
@just3ws
just3ws / .skhdrc
Created November 28, 2020 15:14
Yabai + SKHD config to emulate SizeUp
# SizeUp: Send Window Left
ctrl + alt + cmd - left : yabai -m window --grid 1:2:0:0:1:1
# SizeUp: Send Window Right
ctrl + alt + cmd - right : yabai -m window --grid 1:2:1:0:1:1
# SizeUp: Send Window Up
ctrl + alt + cmd - up : yabai -m window --grid 2:1:0:0:1:1
# SizeUp: Send Window Down
@just3ws
just3ws / de_morgans_laws.rb
Last active November 20, 2018 15:22
De Morgan's laws (in Ruby)
puts "<< De Morgan's laws >>\n\n"
PAIRS = [
[false, true],
[true, false],
[true, true],
[false, false]
]
puts "\"NOT (A AND B)\" is the same as \"(NOT A) OR (NOT B)\""
@just3ws
just3ws / vcr.rb
Created November 5, 2014 15:02
VCR configuration that does a pretty good job of filtering out GitHub, Twitter, and LinkedIn keys.
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :webmock
c.ignore_localhost = true
c.default_cassette_options = { record: :new_episodes }
c.allow_http_connections_when_no_cassette = false
c.configure_rspec_metadata!
c.ignore_hosts 'codeclimate.com'
@just3ws
just3ws / bohater-parkingu.yaml
Last active June 10, 2018 04:23
Bohater Parkingu API 1.0.1
---
openapi: 3.0.0
servers:
- description: Bohater Parkingu Rates API
url: https://virtserver.swaggerhub.com/just3ws/bohater-parkingu/1.0.1
info:
description: Parking rate for a given date and time range.
version: "1.0.1"
title: Bohater Parkingu API
contact:
@just3ws
just3ws / gogodoots.zsh
Created March 20, 2018 15:33
Script to easily run multiple queries for types of files and dump them to a simplified JSON string.
#!/usr/bin/env zsh
# vim:set ft=zsh:
local word="$1"
local filter=".items[] | { repository: .full_name, username: .owner.login, reponame: .name, branch: .default_branch, description: .description }"
local query="q=$word in:path fork:false"
# local query="q=evil fork:false language:\"Emacs Lisp\""
echo -n '{"query": "'
echo -n "$query"
echo '"}'
@just3ws
just3ws / floodwall.rb
Last active October 13, 2017 18:32
Blocks that know where their towel is.
# Rails.configuration.permit_automated_emails = true
class Floodwall
def initialize(context, bypass = false, **data, &action)
@context = context
@data = OpenStruct.new(data || {})
@permit = Rails.configuration.permit_automated_emails || bypass || false
Rails.logger.warn { 'Floodwall has been bypassed and will allow emails through' } if bypass
@just3ws
just3ws / methods.rb
Last active October 13, 2017 16:52
Methods and stuff
class Foo
attr_reader :env
def initialize
@env = 'staging' # Rail.env
end
def bar
warninger(biz: 123, buz: 'Hello', baz: Object.new)
end
@just3ws
just3ws / Enable Logging Insight in Postgres.md
Created September 15, 2017 15:22
Enable Logging Insight in Postgres
vim /usr/local/var/postgres/postgresql.conf

At the end of the file add...

shared_preload_libraries 'pg_stat_statements,auto_explain' # Add settings for extensions here
@just3ws
just3ws / config-initializers-action_controller-notifications.rb
Created September 15, 2017 15:01
ActiveSupport Notification Subscribers for ActionController and ActiveRecord Events
unless Rails.env.production?
ActiveSupport::Notifications.subscribe(/\A.*\.action_controller\z/) do |*args|
ts = Time.now.iso8601
event = ActiveSupport::Notifications::Event.new(*args)
event_name, source_name = event.name.split('.')
unless event_name == 'unpermitted_parameters'
log_file = "#{source_name.tr('_', '-')}-notifications.log"
logger = ActiveSupport::TaggedLogging.new(Logger.new(Rails.root.join('log', log_file)))