Skip to content

Instantly share code, notes, and snippets.

View AlexKott's full-sized avatar
📚

Alexander Kott AlexKott

📚
View GitHub Profile
@AlexKott
AlexKott / UserProfileComponent.js
Created October 11, 2018 08:17
Fetching data in componentDidMount
class UserProfile extends React.Component {
// ...
async componentDidMount() {
const { data } = await httpAdapter.get(`${API_URL}/users/${this.props.userId}`);
this.setState({ user: data.user });
}
// ...
}
@AlexKott
AlexKott / loaderMiddleware.js
Last active September 10, 2018 07:24
You can use this in combination with a request middleware (https://gist.github.com/AlexKott/d0b36882e873ec931d69f5d9cc2c7e7f)
import * as actions from '@/actions';
import * as t from '@/actions/types';
export default store => next => action => {
if (action.type === t.SEND_REQUEST) {
store.dispatch(actions.incrementLoading());
if (!action.payload.onFinally) {
action.payload.onFinally = [];
}
@AlexKott
AlexKott / sendRequestMiddleware.js
Created September 10, 2018 07:20
Example of a more complex request middleware
import * as t from '@/actions/types';
import ajax from '@/adapters';
import getEndpoint from '@/constants/endpoints';
export default store => next => async action => {
const { type, payload } = action;
if (type === t.SEND_REQUEST) {
const {
data,
@AlexKott
AlexKott / package.json.part
Last active July 13, 2017 09:49
Webpack configuration (ejected create-react-app) for including scss and '@' as an alias for the source directory to avoid '../../../'
{
.....
// jest configuration
"moduleNameMapper": {
"^react-native$": "react-native-web",
"^@(.*)$": "<rootDir>/src$1"
}
.....
}
@AlexKott
AlexKott / flatten-array-cli.js
Created March 10, 2017 11:56
Flattens an array of type [1, 2, [3, [4]]] to [1, 2, 3, 4].
/**
Simple (Node.js) CLI for the flatten array function.
**/
const flattenArray = require('./flatten-array');
const colors = {
reset: '\033[0m',
pink: '\033[35m',
red: '\033[31m',
@AlexKott
AlexKott / gist:ba43547cbc3f5171007de3eb434592fa
Last active January 7, 2020 09:21
Export links from Google Spaces
/*
Inspired by https://gist.github.com/daniele-rapagnani/2e7372210726b28aec8f0d2d1d149ffb
This script selects all links on a Google Spaces page with url, title and date.
Reload the page for every space and scroll down to the end (until it says
"The end is just a new beginning.").
Open the browser's console (right click -> inspect -> "Console") and paste these lines.
It then logs it to a HTML string which you can copy and save as "spaces-exports.html".
When changing to another service (e.g. Dropmark, Pocket ...) you can use the html file