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 / 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.debug (with-out-str (pprint query)))
(let [ret (parser env query target)]
(js/console.debug (with-out-str (pprint ret)))
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
(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.

Keybase proof

I hereby claim:

  • I am peeja on github.
  • I am 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) 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]
View mount-bug.rb
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source ''
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
system 'bundle'
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
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.
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 / 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.to_f}>"
BigDecimal(10) # => #<BigDecimal:7fcd7103ee68,'0.1E2',9(36)>
BigDecimal.send(:prepend, ReadableBigDecimal)
BigDecimal(10) # => #<BigDecimal: 10>
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
def write(data)
@ios.each { |io| io.write(data) }
You can’t perform that action at this time.