Skip to content

Instantly share code, notes, and snippets.

View markburns's full-sized avatar
💭
👋

Mark Burns markburns

💭
👋
View GitHub Profile
@christianhujer
christianhujer / treeHighlight.sh
Last active February 2, 2016 05:21
Highlights incoherence in a directory tree.
#!/bin/bash
startDir=$1
wordToFind=$2
for dir in $(find $startDir -type d) ; do
echo -n "$dir:"
for file in $(find $dir --depth 1 -name "*.rb") ; do
if grep $wordToFind $file >/dev/null ; then
echo -n "X"
@splattael
splattael / snafu.rb
Last active September 16, 2016 12:57
"self has wrong type to call super in this context" under weird circumstances
module ThreadSafe
class NonConcurrentCacheBackend
def self.method(key, value)
end
end
class MriCacheBackend < NonConcurrentCacheBackend
WRITE_LOCK = Mutex.new
def self.method(key, value)
@pasberth
pasberth / namespace.rb
Created April 21, 2012 07:00
あるモジュール A の下に宣言されたクラスはすべて A を include するなら、 クラスの宣言を define_class というメソッドを作って行って class_defined が呼ばれるようにしたほうがいいかもしれない
module NameSpaceMethods
def define_class name, superclass=Object, &block
Class.allocate.tap do |klass|
const_set name, klass
klass.send :initialize, superclass, &block
module_or_class_defined klass
class_defined klass
end
end
@pithyless
pithyless / either.rb
Created March 27, 2012 14:44
Chaining Either for Ruby
# A chainable Either monad for Ruby
#
# Examples
#
# Either.right('s') >> proc { |s| Either.right(s + '-1') } >> proc { |s| Either.right(s + '-2') }
# #=> #<Either @left=nil, @right="s-1-2">
#
# Either.right('s') >> proc { |s| Either.left('error!') } >> proc { |s| Either.right(s + '-2') }
# #=> #<Either @left='error!', @right=nil>
#
@whizcreed
whizcreed / gist:1111443
Created July 28, 2011 12:18
Rails how to round time to the current hour. 05:12:03 to 05:00:00
t = Time.now.utc
t.sec.seconds.ago(((t.min).minutes.ago(t)))
# Aditya Raj: http://whizcreed.com
=begin
>> t = Time.now.utc
=> Thu Jul 28 12:13:26 UTC 2011
>> t.sec.seconds.ago(((t.min).minutes.ago(t)))
require 'jruby/profiler'
profile_data = JRuby::Profiler.profile do
# code to be profiled....
end
my_output_stream = java.io.ByteArrayOutputStream.new
print_stream = java.io.PrintStream.new(my_output_stream)
profile_printer = JRuby::Profiler::GraphProfilePrinter.new(profile_data)