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 / long_lines.vim
Created March 22, 2014 10:23
Highlight long lines (>80) and provide a toggle command
" Highlight long lines (>80)
autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929
autocmd BufEnter * match OverLength /\%81v.*/
autocmd BufEnter * let w:long_line_match = 1
fu! LongLineHighlightToggle()
highlight OverLength ctermbg=darkgrey guibg=#592929
if exists('w:long_line_match')
match OverLength //
@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 / gist:3985726
Created October 31, 2012 07:58
test notification posting with #ocmock
- (void)testNotificationWhenEditingNonTodayStat
{
// given
id mock = [OCMockObject observerMock];
[[NSNotificationCenter defaultCenter] addMockObserver:mock name:FGNPastStatWasUpgraded object:nil];
[[mock expect] notificationWithName:FGNPastStatWasUpgraded object:nil];
_this.date = [DLCommon dateFromString:@"2010-04-01"];
// when
_this.reviewedValue++;
@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

{
"_sync": {
"rev": "9-e41acebf2f28b630dd39842c7a7ff625",
"sequence": 194,
"history": {
"revs": [
"1-1a599e6cbbdee78cda1cac87a0055d5a",
"2-484a8bf6e3c4618b5a61bad37d8be150",
"4-b35a1cd9ed8519c649f3d44a18792c27",
"5-e9e0126ed3d91c9c050c4cea76b705cf",
{
"_id" => "_design/Foo",
"language" => "javascript",
"views" => {
"by_name" => {
"map" => "function(doc) {\n if ((doc['type'] == 'Foo') && (doc['name'] != null)) {\n emit(doc['name'], null);\n }\n}\n"
},
"by_tag" => {
"map" => "function(doc) {\n if ((doc['type'] == 'Foo') && (doc['tag'] != null)) {\n emit(doc['tag'], null);\n }\n}\n"
},