Skip to content

Instantly share code, notes, and snippets.

View fabiomcosta's full-sized avatar
:octocat:
void 0

Fabio M. Costa fabiomcosta

:octocat:
void 0
View GitHub Profile
const App: () => React$Node = (props) => {
const [ players, setPlayers ] = useState([]);
useEffect(() => {
AsyncStorage.getItem('@maddness_user').then((userData) => {
getNearbyPlayers().then(performStompConnect);
}
});
}, []);
@fabiomcosta
fabiomcosta / .vimrc
Created June 19, 2012 22:42
Better filetype detection for djangohtml on .html files on VIM. The default one just checks for the existence of `{%\s*\(extends\|block\)` on the first 10 lines, and sometimes, on include files for example, you dont have any of them. Thi
" a better htmldjango detection
augroup filetypedetect
" removes current htmldjango detection located at $VIMRUNTIME/filetype.vim
au! BufNewFile,BufRead *.html
au BufNewFile,BufRead *.html call FThtml()
func! FThtml()
let n = 1
while n < 10 && n < line("$")
if getline(n) =~ '\<DTD\s\+XHTML\s'
@fabiomcosta
fabiomcosta / .flowconfig
Last active July 26, 2020 04:45
Fixing immutable 3.8 Flow types without having to upgrade to v4
[ignore]
.*/node_modules/immutable/.*
@fabiomcosta
fabiomcosta / sync-settimout-snippet.js
Created August 26, 2011 21:06
Mocks the setTimeout function with jasmine, making setTimeout dependent tests synchronous and easier to test.
// inside your beforeEach hook
spyOn(window, 'setTimeout').andCallFake(function(fn){
fn.apply(null, [].slice.call(arguments, 2));
return +new Date;
});
...
/* Polyfill service v3.27.1
* For detailed credits and licence information see https://github.com/financial-times/polyfill-service.
*
* Features requested: IntersectionObserver,IntersectionObserverEntry,default
*
* - IntersectionObserver, License: CC0 */
(function(undefined) {
// IntersectionObserver
# Mixed css-in-js solution
Current css-in-js solutions generaly have 2 different approaches to inserting styles on the page:
1. `style` DOM nodes that have their text `innerHTML` changed
2. static style extration, where a CSS file is created from the inlined JS
`1` is good because it allows applications to support dynamic styles that have their value changed overtime, but they
require a runtime that adds some overhead to the APP and will require the browser to parse the JS code that contains the CSS rules and then the inject CSS.
`2` is good because it allows developers to ship CSS directly to the browser, without the runtime cost.
/*
Copyright (c) 2009 Rob Bast
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software
function x() {
if (foo) {
return foo;
}
if (bar) {
retur bar;
}
return baz;
}
const elementWithRef = shallow(<Component/>).find('<the-ref-element>');
elementWithRef.prop('ref')({ getBoundingClientRect: () => ({ width: 12, ... })});
// do things that would use the ref you just set
/*
---
Port from the YUI3 event-simulate functionality to vanilla javascript.
...
*/
(function(global, document){
var mix = function(obj1, obj2){
for (var key in obj2){
obj1[key] = obj2[key];