Skip to content

Instantly share code, notes, and snippets.

View ddelrio1986's full-sized avatar

Daniel Del Rio ddelrio1986

  • eLearning Innovations
  • Seminole, Florida, United States of America
View GitHub Profile
@ddelrio1986
ddelrio1986 / common.scss
Created February 20, 2024 18:27
Skillways Discourse Theme
:root:not(.admin-area) {
--d-sidebar-width: 0;
}
html:not(.admin-area) {
.alert-emails-disabled,
.d-header,
.sidebar-wrapper {
display: none;
@ddelrio1986
ddelrio1986 / GeneralError.jsx
Created August 16, 2018 16:57
A simple general error component
import React from 'react'
import { Alert, Col, Grid, Row } from 'react-bootstrap'
const GeneralError = () => (
<Grid fluid>
<Row>
<Col xs={12}>
<Alert bsStyle="danger" style={{marginTop: '1em'}}>
<h4 style={{fontWeight: '600'}}>An error has occurred!</h4>
<p>Relaunch the content to ensure nothing is lost.</p>
@ddelrio1986
ddelrio1986 / handle-response.js
Last active August 16, 2018 15:29
Handle fetch errors
export function handleJSONResponse (response) {
return response.json()
.then(json => {
if (response.ok) return json
return Promise.reject({...json, responseObj: response})
})
}
export function handleTextResponse (response) {
<?php
// Example of subclassing the base Exception class. Note that it doesn't HAVE to contain any code.
class FileWriteException extends Exception {
}
// Rule: When writing a function, you should throw exceptions for error management instead of returning a
// boolean.
// Rule: You should never throw Exception class directly. Instead, you should consider extending the Exception
@ddelrio1986
ddelrio1986 / index.js
Created February 8, 2018 14:31
Extend entities in DraftJS when typing next to them.
/*
DraftJS Slack - #general
Jimj 02/08/2018 [8:13 AM]
@ddelrio Simplest solution I found for continuing entities is, in beforeInputHanded :
*/
const prev_char_space = this.getCharFromSelection() === ' '
const new_char_space = char === ' '
const prev_ent = this.getEntityAtSelection()
if (prev_ent && (!prev_char_space || !new_char_space)) {
const contentStateWithEntity = Modifier.insertText(
@ddelrio1986
ddelrio1986 / contentStateLogger.js
Created November 8, 2017 14:18
DraftJS ContentState Logger
export const contentStateLogger = editorState => {
const result = JSON.stringify(convertToRaw(editorState.getCurrentContent()), null, 4);
const newResult = JSON.parse(result);
const contentState = JSON.stringify(newResult, null, 4);
// unquotes object keys
const keyQuotes = /"(.+)"(?=:)/g;
const newContentState = contentState.replace(keyQuotes, '$1');
console.log(newContentState);
};