Skip to content

Instantly share code, notes, and snippets.

View OliverJAsh's full-sized avatar

Oliver Joseph Ash OliverJAsh

View GitHub Profile
// install @types/react-redux and other nonsense
import * as React from 'react'
import { connect } from 'react-redux'
import { YourActualAppState } from './wherever-it-is.ts'
export function mapStateToProps({
whatever
}: YourActualAppState) {
return {
@iansinnott
iansinnott / rx-file-reader.js
Created June 5, 2017 19:36
A simple Rx abstraction over the FileReader API
/**
* Read the text contents of a File or Blob using the FileReader interface.
* This is an async interface so it makes sense to handle it with Rx.
* @param {blob} File | Blob
* @return Observable<string>
*/
const readFile = (blob) => Observable.create(obs => {
if (!(blob instanceof Blob)) {
obs.error(new Error('`blob` must be an instance of File or Blob.'));
return;
function *flatten<T>(iterable: Iterable<T>, depth: number = Infinity): Iterable<T> {
if (depth === 0) { return iterable; }
for (let item of iterable) {
if (typeof item[Symbol.iterator] === 'function') {
yield *flatten(item, depth - 1);
} else {
yield item;
}
}
@threepointone
threepointone / ensure.js
Last active January 13, 2022 10:10
fix for ssr + dynamic imports with webpack
function ensure(moduleId, fn, done){
if(__webpack_modules__[moduleId]) { //eslint-disable-line no-undef
return done(undefined, __webpack_require__(moduleId)) //eslint-disable-line no-undef
}
fn().then(Module => done(undefined, Module), done)
}
// usage
ensure(require.resolveWeak('./x.js'),
@srdjan
srdjan / 100+ different counter apps...
Last active May 6, 2024 05:13
100+ different js counter apps...
100+ different js counter apps...
@dekz
dekz / fstash.zsh
Last active April 12, 2023 00:15
fzf + git stash
fstash() {
local out q k sha
while out=$(
git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" |
fzf --ansi --no-sort --query="$q" --print-query \
--expect=ctrl-d,ctrl-b);
do
IFS=$'\n'; set -f
lines=($(<<< "$out"))
unset IFS; set +f
gstash() {
local out k reflog
out=(
$(git stash list --pretty='%C(yellow)%gd %>(14)%Cgreen%cr %C(blue)%gs' |
fzf --ansi --no-sort --header='enter:show, ctrl-d:diff, ctrl-o:pop, ctrl-y:apply, ctrl-x:drop' \
--preview='git stash show --color=always -p $(cut -d" " -f1 <<< {}) | head -'$LINES \
--preview-window=down:50% --reverse \
--bind='enter:execute(git stash show --color=always -p $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \
--bind='ctrl-d:execute(git diff --color=always $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \
--expect=ctrl-o,ctrl-y,ctrl-x))

general

Keys Action Description
Cmd-Shift-A Search action by name search for any command/menu items
Alt-F1 Select target Open current file in project tree, finder, etc

opening files

Keys Action Description
Cmd-O Class search classes, traits, objects
@paullewis
paullewis / requestIdleCallback.js
Last active February 21, 2024 16:56
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@gaearon
gaearon / slim-redux.js
Last active May 5, 2024 15:14
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {