Skip to content

Instantly share code, notes, and snippets.

View prenaudin's full-sized avatar
🏠
Working from home

Pierre Renaudin prenaudin

🏠
Working from home
View GitHub Profile
@prenaudin
prenaudin / lemonde-dark-mode.css
Last active December 10, 2020 09:53
Le Monde - Dark Mode theme
/* Colors variables */
:root {
--black: #0A111A;
--near-black: #2f2c3c;
--white: #f0f0f0;
--near-white: #D0D0D0;
}
body {
color: --var(white);
@prenaudin
prenaudin / 1 - models-Task--Flow.js
Created June 8, 2016 16:35
Immutable.Record + React + Redux = ❤ - 5
// @flow
import Immutable from 'immutable';
const defaultRecord = {
id: string;
done: boolean;
label: string;
createdAt: string;
updatedAt: string;
@prenaudin
prenaudin / insertCheckbox.js
Last active September 5, 2022 17:36
Add checkboxes to your Draft.js editor - insertCheckbox.js
import { Modifier, EditorState, Entity } from 'draft-js';
export default function insertCheckbox(editorState) {
// Define the checkbox entity
const entityKey = Entity.create('CHECKBOX', 'IMMUTABLE', { checked: false });
// Collapse selection
const selectionState = editorState.getSelection().merge({
anchorOffset: selectionState.getFocusOffset(),
});
@prenaudin
prenaudin / Editor.react.js
Last active September 5, 2022 17:36
Add checkboxes to your Draft.js editor - Editor.react.js
import React from 'react';
import { Editor, KeyBindingUtil, getDefaultKeyBinding } from 'draft-js';
import keycode from 'keycode';
import insertCheckbox from 'modifiers/insertCheckbox';
const { hasCommandModifier } = KeyBindingUtil;
function customKeyBindingFn(e) {
if (hasCommandModifier(e) && e.shiftKey && keycode(e) === 'c') {
return 'insert-checkbox';
@prenaudin
prenaudin / components-TaskListItem.js
Last active June 9, 2016 09:07
Immutable.Record + React + Redux = ❤ - 5
import React from 'react';
import Task from 'models/Task';
const TaskListItem = ({ task, onToggleTaskDone }) => (
<div className="task-list-item">
<input
type="checkbox"
checked={task.isDone()}
onChange={onToggleTaskDone}
/>
@prenaudin
prenaudin / containers-TaskListContainer.js
Last active June 9, 2016 09:13
Immutable.Record + React + Redux = ❤ - 4
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { toggleTaskDone } from 'actions/tasks';
import TaskMap from 'models/TaskMap';
import TaskListLayout from 'components/Task/List/Layout';
const TaskListContainer = ({ onToggleTaskDone, tasks }) => (
<TaskListLayout>
{ tasks.map((task) =>
@prenaudin
prenaudin / reducers-tasks.js
Last active June 9, 2016 09:13
Immutable.Record + React + Redux = ❤ - 3
import { RECEIVED_ENTITIES, DELETE_TASK, TOGGLE_TASK_DONE } from 'constants/ActionsTypes';
import Task from 'models/Task';
import TaskMap from 'models/TaskMap';
const initialState = new TaskMap();
const mergeEntities = (state, newTasks) =>
state.merge(newTasks.map((task) => new Task(task)))
export default (state = initialState, action) =>
@prenaudin
prenaudin / models-TaskMap.js
Last active June 3, 2016 13:19
Immutable.Record + React + Redux = ❤ - 2
import Immutable from 'immutable';
const TaskMap = Immutable.OrderedMap;
export default TaskMap;
@prenaudin
prenaudin / 1 - models-Task.js
Last active June 7, 2016 14:47
Immutable.Record + React + Redux = ❤ - 1
import Immutable from 'immutable';
const TaskRecord = Immutable.Record({
id: null,
done: false,
label: '',
createdAt: null,
updatedAt: null,
})
@prenaudin
prenaudin / css-rules.js
Created June 25, 2014 15:51
Show Number of CSS Rules on a web page
function countCSSRules() {
var results = '',
log = '';
if (!document.styleSheets) {
return;
}
for (var i = 0; i < document.styleSheets.length; i++) {
countSheet(document.styleSheets[i]);
}
function countSheet(sheet) {