Skip to content

Instantly share code, notes, and snippets.

View mik01aj's full-sized avatar

Mikołaj D. mik01aj

  • independent
  • Munich
View GitHub Profile
@mik01aj
mik01aj / mochatest.js
Last active July 3, 2018 17:51
Running integration test for react-styleguidist styleguide
/* eslint max-nested-callbacks: 0, no-console: 0 */
/* global STYLEGUIDE_LOADER_OPTIONS:false */
console.log('\n\n*** RUNNING TEST ***');
var _ = require('lodash');
var babel = require('babel-core');
var babelConfig = require('../package.json').babel;
var React = require('react');
var TestUtils = require('react-addons-test-utils');
@mik01aj
mik01aj / Comparison.md
Last active November 28, 2015 14:45
Comparison of flying-squirrel and Falcor

The common part

Both flying-squirrel and Falcor:

  • Are data fetching libraries
  • Use virtual JSON tree for data modelling
  • Help a lot in keeping the APIs consistent
  • Have client part and server part
  • Handle references efficiently, avoiding roundtrips to server and duplicated data
  • Have routing on the server side, with routes doing just one simple thing.
@mik01aj
mik01aj / SquirrelWrapper.jsx
Created August 21, 2015 09:34
A wrapper for using flying-squirrel with React
/** @jsx React.DOM */
'use strict';
var React = require('react');
var squirrelClient = require('../squirrelClient');
// FIXME: using lastRender for freezing the component doesn't work. skipping some updates with
// shouldComponentUpdate doesn't as well. The problem is that when the user clicks something, it
// triggers a setState on some descendant component and not on SquirrelWrapper. And this partial
@mik01aj
mik01aj / README.md
Last active April 21, 2017 13:02
How to use Tether with React

Tether is a great library for positioning stuff (tooltips, modals, hints, etc) in your web app.

But, as I use React, it was pretty problematic for me, as Tether mutates the DOM and React breaks miserably when it sees mutated DOM. The solution is to have the tethered element outside the part of the DOM tree which is controlled by React (in this case, I use document.body).

That's why I created 2 helpers to use Tether with React.

The first one, TetheredElement is a plain JS helper to create a new element, attach it to some other one via Tether, and populate it with some React component.

The second one, TetherTarget is a React component and it uses TetheredElement to integrate it further with React, so that you can attach components to each other with Tether, without leaving the cozy React/JSX world and worrying about manual DOM operations. Just write:

@mik01aj
mik01aj / package.json
Last active August 29, 2015 14:27
iron-node bug #45
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "suite.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@mik01aj
mik01aj / ModelStore-test.js
Created March 17, 2015 11:27
ModelStore - A simple tool to gather data requests from frontend to batch queries. See 2nd unit test for usage example.
/*jshint jasmine: true */
'use strict';
var ModelStore = require('../ModelStore');
var Promise = require('es6-promise').Promise;
var _ = require('lodash');
describe('ModelStore', function () {
var mockFunctionForTheThingApi, axiosGetSpy, store;
@mik01aj
mik01aj / pdf-autoselect.sh
Created February 21, 2015 17:52
A script to filter out repeated partial slides in PDF presentations (especially lecture slides made in LaTeX Beamer) and generate a printer-friendly version.
#!/bin/bash
# Autor: Mikołaj Dądela <[email protected]>
inputPdf="$1"
threshold="10"
if [ "$inputPdf" == "" ]; then
echo "Usage: $0 input.pdf [output.pdf] [<threshold>]"
@mik01aj
mik01aj / gulpfile.js
Created February 10, 2015 12:10
A hackish way to re-run tests just for the changed file. (Gulp + Jest)
// ... requires, initialization and stuff ...
function runJest(changedFilePath) {
var nodeModules = path.resolve('./node_modules');
var jestConfig = {
scriptPreprocessor: nodeModules + '/gulp-jest/preprocessor.js',
unmockedModulePathPatterns: [nodeModules + '/react'],
moduleFileExtensions: ['js', 'jsx'],
testFileExtensions: ['js', 'jsx'],
};
#!/bin/bash
# Usage: ./gen.sh collected-stacks.txt
TMPSTACKS=/tmp/flamegraph-stacks-collapsed.txt
TMPPALETTE=/tmp/flamegraph-palette.map
./stackcollapse-jstack.pl $1 > $TMPSTACKS
# 1st run - hot: default
@mik01aj
mik01aj / gist:6871418
Created October 7, 2013 17:10
simple routes in js
const varRegex = /:([a-zA-Z][a-zA-Z0-9]*)/g;
function Route(template) {
this.pack = function pack(data) {
const varRegexClone = new RegExp(varRegex);
return template.replace(varRegex, function (m) {
const key = varRegexClone.exec(m)[1];
varRegexClone.lastIndex = 0; // resetting regex object
return data[key];
});
};