Skip to content

Instantly share code, notes, and snippets.

View markburns's full-sized avatar
💭
👋

Mark Burns markburns

💭
👋
View GitHub Profile
@markburns
markburns / a.rb
Last active July 13, 2017 12:08
Defining methods at the top level scope
#!/usr/bin/env ruby
def do_something_probably_just_in_this_script!
puts "called in #{self} from #{caller[-1]}"
end
module HeresAnother
def this_one
puts "called in #{self} from #{caller[-1]}"
end
@markburns
markburns / delfos_queries_ab.errors
Last active June 27, 2017 13:25
delfos bundler errors
{"step_number":1,"stack_uuid":"7b5a17fa-8abc-4dda-854b-a251b4d2593a","call_site_file":"spec/bundler/plugin/api/source_spec.rb","call_site_line_number":10,"container_method_klass_name":"RSpec::ExampleGroups::BundlerPluginAPISource::Attributes","container_method_type":"InstanceMethod","container_method_name":"source","container_method_file":"/Users/markburns/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/memoized_helpers.rb","container_method_line_number":295,"called_method_klass_name":null,"called_method_type":"InstanceMethod","called_method_name":"initialize","called_method_file":"lib/bundler/plugin/api/source.rb","called_method_line_number":47}
{"step_number":1,"stack_uuid":"810ec287-64bd-4241-9924-ff5f958f62e5","call_site_file":"spec/bundler/plugin/api/source_spec.rb","call_site_line_number":10,"container_method_klass_name":"RSpec::ExampleGroups::BundlerPluginAPISource::Attributes","container_method_type":"InstanceMethod","container_method_name":"source","container_method_fil
require "binding_of_caller"
Thread.current[:current_thread_local_info] = "value set inside (main)"
class A
def something
t = Thread.new do
Thread.current[:current_thread_local_info] = "value set inside A#something"
B.new.another_thing
@markburns
markburns / current-branch
Last active August 18, 2017 16:13
useful bash scripts for finding files/changed files/running specs etc
#!/usr/bin/env bash
git rev-parse --abbrev-ref HEAD | tail -2
alias show-changed-directories="gd master --name-only | sort | sed -e 's/\/[^\/]*rb$//' |sed -e 's/\/.*\.js$//' | sed -e 's/\/.*\.haml$//' | sed -e 's/\/.*yml$//' | sort | uniq"
alias show-changed-specs="git diff master --name-only | grep spec.rb "
alias run-changed-specs="show-changed-specs | xargs zeus rspec"
alias update-pr="git checkout master && git pull --rebase && git checkout - && git rebase master"
alias docker-env-eval='eval "$(docker-machine env default)"'
alias docker-machine-refresh='(docker-machine stop || docker-machine kill) ; docker-machine start; docker-env-eval'
alias docker-setup="yes | docker-machine regenerate-certs && docker-env-eval && docker-machine start default"
#!/usr/bin/env bash
function exists(){
while read line
do
if [ -e $line ]
then
echo $line
fi
done < "${1:-/dev/stdin}"
}
@markburns
markburns / app__example_code.rb
Last active February 7, 2017 19:48
Print out /fails tests if class instance variables defined in your application code
# Example sets some state
class SomeObject
def self.asdf
@a = 1
end
end
SomeObject.asdf
git-expert () {
git log --all $1 | sed "s/.*\[\(.*\)\].*/\1/g" 2>/dev/null | sort | uniq -c | sort -r
}
/Users/markburns/code/delfos/lib/delfos/call_stack.rb:18: [BUG] Segmentation fault at 0x00000000000038
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin14]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
@markburns
markburns / show_class_instance_variables.rb
Last active December 25, 2016 07:15
If you ever use class instance variables, you'll run into state hell. This recursively searches a namespace for any instance variables and prints them out. Skipping circular constant definitions
def show_class_instance_variables(n)
puts "#{n} #{n.instance_variables}" if n.instance_variables.length.positive?
return unless (n.is_a?(Class) || n.is_a?(Module))
n.constants.each do |c|
next if n==c
klass = n.const_get(c)
if klass.is_a?(Class) || klass.is_a?(Module)