Skip to content

Instantly share code, notes, and snippets.

function egg() {
console.log("cluck!");
return chicken;
}
function chicken() {
console.log("plop!");
return egg;
}
@tomsotte
tomsotte / demonkeypatch.js
Created September 3, 2022 18:58
Track window properties re-assignments and monkey-patching
// Inject before other scripts in the page
(function () {
const windowInitial = Object.assign({}, window);
window._isMP = function () {
return Object.keys(window).filter(
(key) => window[key] !== windowInitial[key]
);
};
// Call window._isMP() to get a list of key that changed on window
})();
@tomsotte
tomsotte / multi-column-section-list-example.md
Last active February 6, 2023 13:06 — forked from robinheinze/multi-column-section-list-example.md
Multi-column SectionList using FlatList

First, let's assemble the data. Say we have two sets of objects: Fruits and Vegetables.

Our sections array would look like this. Note how each section has a data attribute, which is an array of our fruits or vegetables.:

const sections = [
  {
    title: 'Vegetables',
    key: 'vegetables',
    data: [
@tomsotte
tomsotte / no-reaction-observable-changes.md
Last active August 4, 2020 08:53
Notes on Mobx, Typescript/Flow, Babel and React

No reaction when an @observable changes

TLDR

To make @observable an optional class attribute, always set a default value, even if it's undefined.

Example

store.ts

// handlers.ts
export function sendEmail(data: EmailData) {
// send email
}
//events.ts
// La classe EventsBus è pressochè inutile, si potrebbe rimpiazzare con un file .d.ts che ne dichiara i tipi
// che un EventEmitter qualsiasi che exportiamo abbia certi on() ed i corrispettivi tipi su emit()
#!/usr/bin/env node
'use strict';
// Interleaving the output of stdout and stderr is unpredictable and can't be
// expressed as a test. What I've tried so far to make it predictable:
// - process.stdout._handle.setBlocking(true)
// - process.stdout.once('drain', () => process.stderr.write('2'));
// - process.stdout.write('1', () => process.stderr.write('2'));
// - await delay() between calls; it works but with varying ms, based on load
// - console.log/error
@tomsotte
tomsotte / gtk.css
Created September 20, 2017 09:48
Gnome-PRO LightBlue 1.2 - fixed some warnings
* {
background-clip: padding-box;
-GtkToolButton-icon-spacing: 4;
-GtkTextView-error-underline-color: #FC4138;
-GtkScrolledWindow-scrollbar-spacing: 0;
-GtkToolItemGroup-expander-size: 11;
-GtkWidget-text-handle-width: 20;
-GtkWidget-text-handle-height: 20;
-GtkDialog-button-spacing: 4;
-GtkDialog-action-area-border: 0;
@tomsotte
tomsotte / centerwidget.cpp
Created September 3, 2017 22:04
Qt centered widget container
#include "centerwidget.h"
#include <QHBoxLayout>
CenterWidget::CenterWidget(QWidget* content, QWidget* parent) : QWidget(parent)
{
QHBoxLayout* l = new QHBoxLayout();
l->addStretch();
l->addWidget(content);
l->addStretch();
@tomsotte
tomsotte / es6-class-json-stringify.js
Created January 30, 2017 19:54
Static/Instance method "toJSON" override in a ES6 Class
// Node 7.4.0
class TestJSON {
static toJSON() {
return 'hey static json';
}
toJSON() {
return 'hi instance json';
}
@tomsotte
tomsotte / request-promise-chaining.js
Last active January 27, 2017 14:30
request-promise-native chaining es6 promises and requests and returns
const request = require('request-promise-native');
function reqGood(n) {
return request('http://google.com/')
.then( (body) => {
// assuming it's always good
console.log('show req', n);
return 'body '+n;
})
.catch( (err) => {