Skip to content

Instantly share code, notes, and snippets.

@jsonberry
jsonberry / word-break-cross-browser.scss
Created October 24, 2017 18:26
Cross / Legacy browser support for word wrapping
.container {
word-wrap: break-word; // works for IE11, IE10
overflow-wrap: break-word; // New naming for word-wrap attribute, keep for possible deprecation of word-wrap
word-break: break-word; // Helps with non English character wrapping, supported by Blink based browsers
.item {
// display: block or inline-block may be required
max-width: 250px;
width: 100%; // Allows for word wrap in IE10/IE11
@jsonberry
jsonberry / helpful-javascript-utilities.js
Last active September 20, 2022 01:33
Helpful JavaScript Utilities
// zip arrays together
// Catalin Dumitru @colin_dumitru
// Jason Awbrey @jsawbrey
const zip = (a, b) => a.map((n, i) => [n, b[i]])
// merge objects in an array together
// caution: properties are overridden if duplicated
// @a [{a},{b}]
// @returns [{a, b}]
// Jason Awbrey @jsawbrey
/// Breakpoints
/// @author Jason Awbrey
/// @param { phone | tablet-portrait | tablet-landscape | desktop | desktop-big } $type [no default]
/// @return { Number } Rem calculated value for a given breakpoint
@function bp($type) {
/// @prop
$breakpoints: (phone: 599, tablet-portrait: 600, tablet-landscape: 900, desktop: 1200, desktop-big: 1800);
@if (map-has-key($breakpoints, $type) != true) {
@error "$type must be one of these: #{map-keys($breakpoints)}";
}
@jsonberry
jsonberry / actions.js
Last active November 9, 2018 21:23
Angular ngrx-router-store Router Actions / Effects
/* tslint:disable:max-classes-per-file */
import {Action} from '@ngrx/store';
import {NavigationExtras} from '@angular/router';
export enum RouterActionTypes {
GO = '[router] Go',
BACK = '[router] Back',
FORWARD = '[router] Forward',
}
@jsonberry
jsonberry / tapLog.ts
Last active January 9, 2019 00:14
rxjs-toolkit examples
import { of } from 'rxjs';
import { tapLog } from 'rxjs-toolkit';
of('hello').pipe(
tapLog(), // log out whatever the signal is, so "hello"
tapLog('labelFoo') // give it a label, { labelFoo: "hello" }
).subscribe()
@jsonberry
jsonberry / ignoreFalsyValues.ts
Last active January 13, 2019 18:48
rxjs-examples
import { from } from 'rxjs';
import { ignoreFalsySignals, tapLog } from 'rxjs-toolkit';
from([
'I',
false,
'am',
null,
'truthy',
]).pipe(
@jsonberry
jsonberry / ignoreFalsyValues.ts
Last active January 14, 2019 17:01
rxjs-examples
import { someDataSource } from './some-api.service';
import { ignoreFalsySignals, tapLog } from 'rxjs-toolkit';
interface Signal {
foo: string;
}
/**
* signals$ pushes out an Observable of Signal
* imagine the source of the stream is the return from an API call
@jsonberry
jsonberry / propsAreTruthy.ts
Last active January 14, 2019 16:58
rxjs-toolkit examples
import { from } from 'rxjs';
import { propsAreTruthy, tapLog } from 'rxjs-toolkit';
const topLevelTruthy = {
one: 'I',
two: 'am',
three: 'truthy',
iHaveNestedProps: { // top level also truthy
nested: null,
},
@jsonberry
jsonberry / propsAreTruthy.ts
Last active January 13, 2019 19:05
rxjs-toolkit examples
import { of } from 'rxjs';
import { propsAreTruthy, tapLog } from 'rxjs-toolkit';
const source$ = of({
foo: {
bar: {
baz: 'truthy!',
},
},
zap: {
@jsonberry
jsonberry / composability.ts
Last active January 9, 2019 03:39
rxjs-toolkit examples
import { someApiService } from './some-api.service';
import { propsAreTruthy, ignoreFalsySignals } from 'rxjs-toolkit';
// imagine getSource$ return an object like this:
const exampleSource = {
id: '123',
origin: {
name: '',
url: 'noop.com',
}