Skip to content

Instantly share code, notes, and snippets.

Avatar
💯
%0

dmitrizzle

💯
%0
View GitHub Profile
@dmitrizzle
dmitrizzle / .babelrc
Last active Jun 27, 2019
Dynamically install polyfills for outdated browsers with Babel 7 and core-js
View .babelrc
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": 3
}
]
],
View client.js
import loadPolyfills from './load-polyfills';
import mountApp from './app'; // the entry point for the rest of my app
loadPolyfills().then(mountApp);
@dmitrizzle
dmitrizzle / string-trim-to-sentence.js
Last active Jan 24, 2018
Trim string by total number of characters, but round to nearest sentence (ceiling)
View string-trim-to-sentence.js
const trimByCharToSentence = (text = "", chars = 0) => {
// string is broken down into sentences;
// this is done by splitting it into array between
// the most common sentence-ending punctuation marks:
// period, exclaimation, ellipsis and question mark;
// if string consists of a single statement, make an array
// anyways
const sentences = text.match(/[^\.!…\?]+[\.!…\?]+/g) || [text]
// store
let result = ""
@dmitrizzle
dmitrizzle / Dots.js
Created Jan 11, 2018
A components for displaying "loading" dots with CSS (for ReactJS and Styled Components)
View Dots.js
// tools
import React from "react"
import styled from "styled-components"
// styles
const Dots = styled.span`
&::after {
display: inline-block;
animation: ellipsis 1.25s infinite;
content: ".";
@dmitrizzle
dmitrizzle / Ajax.js
Created Jan 8, 2018
A simple Ajax utility to send and receive requests with vanilla JavaScript
View Ajax.js
function Ajax(url, fn) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var data = JSON.parse(request.responseText);
fn(data);
} else {
console.log("Error. Server connection OK.", request.responseText);
}
View Slate Placeholder
const wrapperStyle = {
position: 'relative'
}
const PlaceHolder = React.createClass({
renderPlaceholder(){
const { node, state, parent } = this.props;
const placeholderText = node.data.get('placeholderText');
return (
@dmitrizzle
dmitrizzle / plugins.js
Created May 29, 2017
Plugin config for Slate using "slate-auto-replace"
View plugins.js
export const plugins = [
AutoReplace({
trigger: "*",
before: /(\*)(.*)/,
ignoreIn: "heading",
transform: (transform, e, data, matches) => {
return transform
.addMark({ type: "bold" })
.insertText(matches.before[2])
.removeMark({ type: "bold" })