Skip to content

Instantly share code, notes, and snippets.

@KidkArolis
KidkArolis / webpack.config.js
Last active October 16, 2023 04:00
Webpack for AMD projects
/**
* Example webpack.config.js for an AMD project (or AMD + CJS mixed project).
* This file should be at the root of your project.
*
* This can then be used in combination with Karma as well
* Just load this file and pass it to karma.webpack key
* (see https://github.com/webpack/karma-webpack#alternative-usage)
*
* This example is a bit extreme. Typically in webpack, you don't need much
* configuration if you have nicely behaving code and work with correctly
/*
Install this hook in app.hooks.js
module.exports = app => {
app.hooks({
before: {
all: [
addParamsForward()
]
}
@KidkArolis
KidkArolis / shell.sh
Created October 10, 2015 20:50
karma start --grep examples
# build and run all tests
$ karma start
# build and run only those tests that are in this dir
$ karma start --grep app/modules/sidebar/tests
# build and run only this test file
$ karma start --grep app/modules/sidebar/tests/animation_test.js
@KidkArolis
KidkArolis / feathers.js
Created November 20, 2019 17:24
Feathers Client with robust reauthentication
import createFeathersClient from '@feathersjs/feathers'
import auth from '@feathersjs/authentication-client'
import socketio from '@feathersjs/socketio-client'
import io from 'socket.io-client'
export function createFeathers() {
const socket = io()
const feathers = createFeathersClient()
feathers.configure(socketio(socket))
feathers.configure(
@KidkArolis
KidkArolis / actions.js
Created November 21, 2018 14:34
Fetch and take latest
import axios from 'axios'
import fetch from './fetch'
export default {
async fetchPage ({ dispatch }, { query, headers }, ref) {
// every time this action is dispatched, make the request using the fetch helper
// which ensures we cancel previous requests and only mutate state after the latest one
await fetch(ref, {
request: cancelToken => {
return Promise.all(
@KidkArolis
KidkArolis / post.md
Last active November 17, 2020 11:21
Designing custom React hooks - sequencing of async effects

We've been building a hooks based REST API wrapper.

A specific use case discussed in this gist is – how do you close a modal after updating a remote resource completes succesfully?

Which of the following options seems best or is there a better approach altogether?

1. Async/Await

function EditNoteModal ({ id, onClose }) {
@KidkArolis
KidkArolis / _intro.md
Last active March 16, 2020 13:22
Feedback on `useMutableSource`

Dear reader,

In the last few years, I've been using my own global store implementation with great success (yes, I'm aware there exist a bazillion "redux like" stores). My one's called tiny-atom.

In particular, the following 4 requirements for a global store emerged from my needs:

1. Batch multiple, rapid store changes

For example, tiny-atom uses requestAnimationFrame to delay/batch the re-renders.

@KidkArolis
KidkArolis / default.yml
Created February 9, 2019 13:01
node-config example
port: 3000
session:
secret: abc
fitbit:
protocol: http
host: localhost:3000
clientId: a
clientSecret: b
@KidkArolis
KidkArolis / Dockerfile
Last active December 13, 2018 13:55
Countly on DigitalOcean
FROM countly/countly-server
[Unit]
Description=Playe Controller
[Service]
ExecStart=/usr/bin/node /home/pi/play/play-controller/controller.js
Restart=always
RestartSec=5
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=play-controller