Skip to content

Instantly share code, notes, and snippets.

View bloadvenro's full-sized avatar

Viktor bloadvenro

View GitHub Profile
@bloadvenro
bloadvenro / fallback-rule.ts
Last active February 3, 2018 18:02
Webpack boilerplate stuff
const fallbackRule: Webpack.Rule = {
test: function matchEverything() {
return true
},
exclude: [
/\.html$/, // .html files are handled by html-webpack-plugin.
/\.json$/ // .json files are often handled by webpack internally (i.e. hot-update.json).
],
loader: require.resolve('file-loader'),
options: {
@bloadvenro
bloadvenro / grub.cfg
Created February 11, 2018 21:39 — forked from Pysis868/grub.cfg
My own configuration file for GRUB2 to boot various live distributions of Linux-based operating systems, along with some system tools. I tried to include a lot of sample configuration entries, even if I don't currently use them, so it may help others. Exceedingly long blog post: http://tehfishyblog.logdown.com/chips/306146-a-homemade-ultimate-bo…
# Config for GNU GRand Unified Bootloader (GRUB) (2)
# /boot/grub/grub.cfg
# or
# /boot/grub2/grub.cfg
# This grub.cfg file was created by Lance http://www.pendrivelinux.com
# Suggested Entries and the suggestor, if available, will also be noted.
# and then improved by Pysis.
@bloadvenro
bloadvenro / redux-is-smarter-than-you-think.md
Created March 10, 2018 14:58 — forked from armw4/redux-is-smarter-than-you-think.md
Optimizing your react components via redux....shouldComponentUpdate for free and more...

The Beginning

Yes...it's true...redux is smart....smarter than you even know. It really does want to help you. It strives to be sane and easy to reason about. With that being said, redux gives you optimizations for free that you probably were completely unaware of.

connect()

connect is the most important thing in redux land IMO. This is where you tie the not between redux and your underlying components. You usually take state and propogate it down your component hiearchy in the form of props. From there, presentational

@bloadvenro
bloadvenro / recursive-switch-type.ts
Last active September 12, 2018 11:55
Typescript recursive switch type
type Switch<T, CaseList extends CaseLike[], Default> = {
case: ((...caseList: CaseList) => any) extends ((current: infer C, ...rest: infer R) => any)
? C extends CaseLike // we must ensure in that to access 'case' property of C
? C['case'] extends T
? C['then']
: R extends CaseLike[] // we must ensure in that to pass R as the third argument below
? Switch<T, R, Default>
: never // this branch will never occur: R is always CaseLike[]
: 'this branch will never occur: C is always CaseLike'
: never; // this branch will never occur because of condition below
interface Dispatch<A extends { type: string }> {
(action: A): void;
}
interface StateGetter<S extends { [key: string]: any }> {
(): S;
}
interface ActionReducer<A extends { type: string }, S extends { [key: string]: any }> {
dispatch: Dispatch<A>;
@bloadvenro
bloadvenro / do-on-subscribe.rxjs.operator.ts
Created April 12, 2019 13:48 — forked from evxn/do-on-subscribe.rxjs.operator.ts
rxjs on subscribe hook, callback on subscribe, doOnSubscribe operator, doOnSubscribe pipe, rxjs onSubscribe
import {defer} from 'rxjs/observable/defer';
import {Observable} from 'rxjs/Observable';
/** Example
import {from} from 'rxjs/observable/from';
from([1, 2, 3])
.pipe(doOnSubscribe(() => console.log('subscribed to stream')))
.subscribe(x => console.log(x), null, () => console.log('completed'));
*/

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@bloadvenro
bloadvenro / create-parcel-boilerplate
Last active November 9, 2019 00:33
Easily create Parcel boilerplates (vanillaJS, TS, React, React+TS)
#!/bin/bash
script_dir=$(pwd)
project_home=$1
isEmpty() { [ -z $1 ] ; }
isCliFlag() { [[ $1 == --* ]] ; }
if isEmpty $project_home || isCliFlag $project_home
then
@bloadvenro
bloadvenro / README.md
Created November 20, 2019 06:40
*nix shell tips ant tricks

*nix shell tips ant tricks

@bloadvenro
bloadvenro / add-p.md
Created November 26, 2019 13:00 — forked from mattlewissf/add-p.md
Lightning Talk: Git add -p

git add -p is your friend

git add -p is basically "git add partial (or patch)"

Patch mode allows you to stage parts of a changed file, instead of the entire file. This allows you to make concise, well-crafted commits that make for an easier to read history. This feature can improve the quality of the commits. It also makes it easy to remove parts of the changes in a file that were only there for debugging purposes - prior to the commit without having to go back to the editor.

It allows you to see the changes (delta) to the code that you are trying to add, and lets you add them (or not) separately from each other using an interactive prompt. Here's how to use it:

from the command line, either use

  • git add -p