Skip to content

Instantly share code, notes, and snippets.

require 'rexml/sax2listener'
require 'rexml/parsers/sax2parser'
class MrProper
include REXML::SAX2Listener
BORING_ATTRS = %w(class index package
checkable checked clickable
enabled focusable focused
scrollable long-clickable password
@sofaking
sofaking / jenkins_csp.md
Last active February 26, 2020 14:16
How to relax default Content Security Policy for Jenkins

By default Content Security Policy (CSP) in Jenkins does not allow Cucumber HTML reports to be shown correctly, with styles, embedded images and JS. To fix that one need to relax CSP rules.

In my case, Jenkins is hosted on Ubuntu, so config file is here: /etc/default/jenkins.
CSP settings should be passed via JAVA_ARGS. Just add the following next to your current JAVA_ARGS settings and then restart Jenkins.

JAVA_ARGS="$JAVA_ARGS -Dhudson.model.DirectoryBrowserSupport.CSP=\"sandbox allow-scripts; default-src 'unsafe-inline'; img-src *\""

To be fair, img-src * shouldn't be necessary, because obviously I'm hosting embedded images next to report itself.
But for some reason img-src 'self' didn't work for me. At least for Safari.

@sofaking
sofaking / adb.sh
Created March 3, 2017 10:48
Get battery level via adb
adb shell dumpsys battery | grep level
# http://stackoverflow.com/questions/6335521/git-how-to-revert-2-files-that-are-stubbornly-stuck-at-changed-but-not-committ
git ls-files -m | xargs -I {} git update-index --assume-unchanged {}
# https://unix.stackexchange.com/questions/217883/du-reports-directory-size-as-much-bigger-than-the-sum-of-its-contents
du -shc -- {.[!.],..?,}*
@sofaking
sofaking / .ctags
Created November 23, 2017 16:19
.ctags file for DSL-generated methods
--regex-ruby=/^[[:space:]]*button[[:space:]]:([a-z_]*)/\1/f,DSL/
--regex-ruby=/^[[:space:]]*button[[:space:]]:([a-z_]*)/\1\?/f,DSL/
--regex-ruby=/^[[:space:]]*button[[:space:]]:([a-z_]*)/\1_button/f,DSL/
--regex-ruby=/^[[:space:]]*text_field[[:space:]]:([a-z_]*)/\1=/f,DSL/
@sofaking
sofaking / reset_submodules.sh
Created November 23, 2017 16:22
Reset a git repository with submodules to initial state
git submodule foreach --recursive git reset --hard
git reset --hard
git submodule update --init
git submodule foreach --recursive git submodule update --init
@sofaking
sofaking / bob.rb
Last active May 5, 2020 19:15
"Translation" of Kent Back's 99 bottles of beer Smalltalk version: https://leftsideagile.com/index.php?post/2020/02/16/The-Beginning-of-Extreme-Programming
class Verse
attr_accessor :stream, :count
def self.verse(count, stream)
case
when count < 0 then NegativeVerse.new
when count == 0 then UltimateVerse.new(stream)
when count == 1 then PenultimateVerse.new(stream)
else PrecedingVerse.new(stream).tap { |pv| pv.count = count }
end