Skip to content

Instantly share code, notes, and snippets.

Avatar

Karolis Narkevicius KidkArolis

View GitHub Profile
View addParamsForward.js
/*
Install this hook in app.hooks.js
module.exports = app => {
app.hooks({
before: {
all: [
addParamsForward()
]
}
@KidkArolis
KidkArolis / _intro.md
Last active Mar 16, 2020
Feedback on `useMutableSource`
View _intro.md

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 / feathers.js
Created Nov 20, 2019
Feathers Client with robust reauthentication
View feathers.js
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 / post.md
Last active Nov 17, 2020
Designing custom React hooks - sequencing of async effects
View post.md

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 / default.yml
Created Feb 9, 2019
node-config example
View default.yml
port: 3000
session:
secret: abc
fitbit:
protocol: http
host: localhost:3000
clientId: a
clientSecret: b
@KidkArolis
KidkArolis / Dockerfile
Last active Dec 13, 2018
Countly on DigitalOcean
View Dockerfile
FROM countly/countly-server
@KidkArolis
KidkArolis / actions.js
Created Nov 21, 2018
Fetch and take latest
View actions.js
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(
View gist:b6861b42ddf3a84564577fc166a09e09
[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
View close.js
'use strict'
let express = require('express')
let axios = require('axios')
let server
function once (cb) {
let app = express()
app.get('/foo', (req, res, next) => {
View karma.conf.js
var grep = require('karma-webpack-grep')
var webpackConfig = require('./webpack.config')
module.exports = function (config) {
webpackConfig.plugins = (webpackConfig.plugins || []).concat(grep({
grep: config.grep,
basePath: '.',
testContext: './tests'
}))