Skip to content

Instantly share code, notes, and snippets.

Petra Jaros Peeja

Block or report user

Report or block Peeja

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Peeja
Peeja / logged-parser.cljs
Created Sep 24, 2016
Om Next parser middleware that adds logging for debugging
View logged-parser.cljs
(defn logged-parser [parser]
(fn [env query target]
(js/console.groupCollapsed "parser:" (if target (str "(" target ")") ""))
(js/console.trace)
(js/console.debug (with-out-str (pprint query)))
(let [ret (parser env query target)]
(js/console.debug (with-out-str (pprint ret)))
(js/console.groupEnd)
ret)))
@Peeja
Peeja / rerender.cljs
Created Sep 9, 2016
What it appears to take to re-render the React tree when Figwheel reloads.
View rerender.cljs
;; Re-render when Figwheel reloads.
(gevents/listen js/document.body
"figwheel.js-reload"
(fn []
(let [root-component (om-next/app-root (compassus/get-reconciler a))]
(letfn [(js-vals [o]
(map #(aget o %) (js-keys o)))
;; Finds the children of a React internal instance of a component.
;; That could be a single _renderedComponent or several
;; _renderedChildren.
View keybase.md

Keybase proof

I hereby claim:

  • I am peeja on github.
  • I am peeja (https://keybase.io/peeja) on keybase.
  • I have a public key whose fingerprint is B2B0 C79D FC2C 19FD C31D 4E46 960B 8671 0FDE B8BE

To claim this, I am signing this object:

View using_arrays.rb
time = Time.mktime(2014, 10, 14, 12, 1)
allowed_ranges = [
[11, 59]..[12, 1],
]
formatted_time = [time.hour, time.min]
p allowed_ranges.any? { |range| range.cover?(formatted_time) }
View alias_method_chain_resilient.rb
module AliasMethodChainResilient
# Give us a module which will intercept attempts to alias methods named in
# the keys of method_aliases, and instead alias the methods named in the
# values of method_aliases.
def self.alias_intercepting_module(method_aliases)
Module.new do
define_method :alias_method do |new_name, old_name|
if method_aliases.key?(old_name.to_sym)
super new_name, method_aliases[old_name.to_sym]
else
View mount-bug.rb
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
GEMFILE
system 'bundle'
end
@Peeja
Peeja / hash_map.rb
Created Jul 2, 2013
A new use for Ruby's `protected`.
View hash_map.rb
# Say you're implementing a hash map, and you've got two
# sets of algorithms which are more efficient at
# different sizes:
class HashMap
class << self
def with_values(values)
if values.size > 64
LargeHashMap.new(values)
@Peeja
Peeja / gist:5831155
Created Jun 21, 2013
"The goggles, they do nothing!" `rake db:test:prepare` appears to have become `rake test:prepare` in Rails 4, but the old task still exists and does nothing. http://stackoverflow.com/q/17150529/4937
View gist:5831155
$ rake --trace db:test:prepare
** Invoke db:test:prepare (first_time)
** Execute db:test:prepare
$ rake --trace test:prepare
** Invoke test:prepare (first_time)
** Invoke db:test:prepare (first_time)
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
@Peeja
Peeja / readable_big_decimal.rb
Last active Dec 18, 2015
Look at your code. Now back to me. Now back to your code. Now back to me. Your BigDecimals are now readable.
View readable_big_decimal.rb
module ReadableBigDecimal
def inspect
"<#{self.class.name}: #{self.to_f}>"
end
end
BigDecimal(10) # => #<BigDecimal:7fcd7103ee68,'0.1E2',9(36)>
BigDecimal.send(:prepend, ReadableBigDecimal)
BigDecimal(10) # => #<BigDecimal: 10>
@Peeja
Peeja / tee_io.rb
Created Apr 30, 2013
TeeIO: A method for logging to a file and STDOUT at the same time. Or to any two or more IOs. Greatly inspired by James Edward Grey II.
View tee_io.rb
class TeeIO
# TeeIO will write to each of these IOs when it is written to.
def initialize(*ios)
@ios = ios
end
def write(data)
@ios.each { |io| io.write(data) }
end
You can’t perform that action at this time.