Skip to content

Instantly share code, notes, and snippets.

@Peeja
Peeja / useObservable.test.ts
Created September 17, 2021 01:47
Read the latest value of an Observable in a React hook (WIP, stashed from another project when it became unnecessary.)
/**
* @jest-environment jsdom
*/
import { useObservable } from "./useObservable";
import { renderHook, act } from "@testing-library/react-hooks";
import { Subject } from "rxjs";
describe("useObservable()", () => {
it("returns each value emitted by the Observable", () => {
@Peeja
Peeja / tee_io.rb
Created April 30, 2013 15:15
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.
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
type PathSegments<Path extends string, Segments = never> = Path extends `${infer Segment}/${infer Rest}` ? PathSegments<Rest, Segments | Segment> : Segments | Path;
type ParamSegments<S extends string> = S extends `:${infer P}` ? P : never;
let segments: PathSegments<'/posts/:id/comments/:comment_id'>;
interface Routes {
match<Path extends string>(path: Path, cb: (params: Record<ParamSegments<PathSegments<Path>>, string>) => void): void;
}
declare const routes: Routes
@Peeja
Peeja / Gemfile
Created December 3, 2012 22:04 — forked from rsutphin/Gemfile
RSpec rcov task does not work
source :rubygems
gem 'rake'
gem 'rspec', '2.12.0'
gem 'rcov'
@Peeja
Peeja / rerender.cljs
Created September 9, 2016 23:00
What it appears to take to re-render the React tree when Figwheel reloads.
;; 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.
@Peeja
Peeja / logged-parser.cljs
Created September 24, 2016 16:28
Om Next parser middleware that adds logging for debugging
(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 / Email appears to be from Andy Lindeman.png
Created November 25, 2012 00:38
GitHub email notification "bug" in Gmail: Gmail conflates senders in list view
Email appears to be from Andy Lindeman.png
@Peeja
Peeja / gist:5831155
Created June 21, 2013 13:33
"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
$ 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 / hash_map.rb
Created July 2, 2013 01:12
A new use for Ruby's `protected`.
# 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)