Skip to content

Instantly share code, notes, and snippets.

export function toLines(s1: Observable<{ toString() }>) {
let lines$ = new Subject<string>()
let acu = ''
s1.subscribe({
next: x => {
acu += x.toString()
if (!acu.includes('\n')) return
let lines = acu.split('\n')
let last = lines.pop()
@fgarcia
fgarcia / ajv.js
Last active February 13, 2019 14:20
Central definition schema with AJV + dynamic definitions
// Objective: Define all schema definitions within a single schema '$id: core'
// + add definitions dynamically
it.only('extend Ajv definitions', async () => {
let res
let core1 = {
$id: 'core',
definitions: {
first: {
type: 'object',
@fgarcia
fgarcia / main.md
Last active January 22, 2019 22:29
Composition Root and Service Locator

If a program needs to make an API call, it is very likely that there is an ApiClient class to make http requests.

let api = new ApiClient('https://api.bank.com')
let bank = new BankFacade(api)

Since I consider an http request as something very basic in any app, I like having this in my runtime

@fgarcia
fgarcia / output.txt
Last active October 7, 2017 11:50
Reset EventEmitter2
> node test.js
Start test
Catch!
end
Start test
Catch!
Catch!
> npm --version
3.10.6
> node --version
v6.3.1
> jest --debug
jest version = 15.1.1
test framework = jasmine2
config = {
@fgarcia
fgarcia / gist:792add55aee5751ef32b
Last active March 20, 2016 22:32
On Dry types

Should a dry type behave more like a Hash?

Goal: ease transition / refactoring of existing code base

Functions like .keys, .values, .map are missing

Having them would make Dry Structs/Values a perfect drop-in replacement for Hash objects

Maybe a standard mixin to "extend this dirty functionality" would be great Any reason why those functions are not provided? It would be the most Ruby idiomatic

@fgarcia
fgarcia / gist:61ae715aa5d8c3bcf2a3
Created April 26, 2015 11:44
multiple #yard gems #ruby
libraries = {}
gems = %w(poconf)
gems.each do |gem_name|
Gem.source_index.find_name(gem_name).each do |spec|
libraries[spec.name] ||= []
libraries[spec.name] << YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)
end
end
YARD::Server::RackAdapter.setup
@fgarcia
fgarcia / gist:09667f7c88e12ea81412
Last active August 29, 2015 14:16
Some quick references for Event Sourcing
Mathias Verraes is one of my first references for beginners of Event Sourcing, his blog is full of goodness. As starting video:
http://verraes.net/2014/03/practical-event-sourcing/
Some talks of Emanuele DelBono like
https://www.youtube.com/watch?v=Vn34CdkLa3g
http://de.slideshare.net/emadb/wroclove-rb
For a VERY basic start, Ruby focused:
https://ianunruh.com/2013/08/event-sourcing-ruby.html
@fgarcia
fgarcia / gist:0d115f9fbe002b5d6922
Created February 9, 2015 14:51
Play with include vs exclude
module Temp
def say
p "hi Parent"
end
end
class Swap
include Temp
def say
@fgarcia
fgarcia / gist:4ce7d571b84d54338e9b
Created February 9, 2015 10:02
Delegation pitfals vs extend
require 'delegate'
class Person
def greeting
'hello'
end
def speak
greeting
end