Skip to content

Instantly share code, notes, and snippets.

View dmitrizzle's full-sized avatar
📸
🎞

dmitrizzle

📸
🎞
View GitHub Profile
@dmitrizzle
dmitrizzle / plugins.js
Created May 29, 2017 14:59
Plugin config for Slate using "slate-auto-replace"
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" })
const wrapperStyle = {
position: 'relative'
}
const PlaceHolder = React.createClass({
renderPlaceholder(){
const { node, state, parent } = this.props;
const placeholderText = node.data.get('placeholderText');
return (
@dmitrizzle
dmitrizzle / Ajax.js
Created January 8, 2018 12:21
A simple Ajax utility to send and receive requests with vanilla JavaScript
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);
}
@dmitrizzle
dmitrizzle / Dots.js
Created January 11, 2018 14:59
A components for displaying "loading" dots with CSS (for ReactJS and Styled Components)
// 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 / string-trim-to-sentence.js
Last active January 24, 2018 16:46
Trim string by total number of characters, but round to nearest sentence (ceiling)
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 = ""
import loadPolyfills from './load-polyfills';
import mountApp from './app'; // the entry point for the rest of my app
loadPolyfills().then(mountApp);
@dmitrizzle
dmitrizzle / .babelrc
Last active June 27, 2019 20:05
Dynamically install polyfills for outdated browsers with Babel 7 and core-js
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "entry",
"corejs": 3
}
]
],