Skip to content

Instantly share code, notes, and snippets.

Avatar

Lawrence Aberba aberba

View GitHub Profile
View markdown draft-js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Draft • Decorators</title>
<link rel="stylesheet" href="../../dist/Draft.css" />
</head>
<body>
<div id="target"></div>
<script src="../../node_modules/react/dist/react.js"></script>
@aberba
aberba / RichEditor.js
Created Dec 30, 2020 — forked from paulinep/RichEditor.js
Draft js editor with images and videos
View RichEditor.js
import React, {Component} from 'react'
import ReactDOM from 'react-dom';
import { EditorState, RichUtils,Editor, ContentState, DefaultDraftBlockRenderMap, convertFromHTML, getSafeBodyFromHTML, AtomicBlockUtils, CompositeDecorator} from 'draft-js';
import createImagePlugin from "draft-js-image-plugin";
import './rich-editor.scss'
import * as Immutable from "immutable";
import {stateToHTML} from 'draft-js-export-html';
import {InlineStyleControls, BlockStyleControls} from './StyleButton'
import Svg from 'common/Svg';
import createVideoPlugin from 'draft-js-video-plugin';
@aberba
aberba / app.es6
Last active Dec 30, 2020 — forked from sisodiaa/app.es6
A sample DraftJS editor for adding image
View app.es6
import React from 'react';
import ReactDOM from 'react-dom';
import {AtomicBlockUtils, Editor, EditorState, Entity, RichUtils, convertToRaw} from 'draft-js';
class MyEditor extends React.Component {
constructor(props) {
super(props);
this.state = {editorState: EditorState.createEmpty()};
@aberba
aberba / hidapi-enum-tst.c
Created Nov 16, 2020 — forked from todbot/hidapi-enum-tst.c
hidapi list devices
View hidapi-enum-tst.c
// hidapi-enum-tst.c -- Demonstrate enumerating
//
// Build with: (assumes you have checked out 'hidapi' into a side directory)
// Mac:
// gcc -I ../hidapi/hidapi ../hidapi/mac/hid.c -framework IOKit -framework CoreFoundation hidapi-enum-tst.c -o hidapi-enum-tst
// Linux (hidraw):
// gcc -I ../hidapi/hidapi ../hidapi/linux/hid.c -ludev hidapi-enum-tst.c -o hidapi-enum-tst
// Linux (libusb):
// gcc -I ../hidapi/hidapi -I /usr/include/libusb-1.0 ../hidapi/libusb/hid.c -lpthread -lusb-1.0 hidapi-enum-tst.c -o hidapi-enum-tst
//
View hidapi.d
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
View sample2.d
module app;
import std.stdio;
import std.experimental.logger: trace;
import std.conv;
import gio.Application : GApplication = Application;
import gtk.Main;
import gtk.Application;
@aberba
aberba / encryption.js
Created Oct 12, 2020 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
View encryption.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
View useForm.js
import { useState, useEffect, useRef } from "react";
export default function useForm({
callback,
validate,
defaultValues = {},
defaultErrors = {}
}) {
const [values, setValues] = useState({});
const [errors, setErrors] = useState({});
@aberba
aberba / feature-flags.md
Created Aug 8, 2020 — forked from threepointone/feature-flags.md
Feature flags: why, how, all that
View feature-flags.md

(I'm enjoying doing these raw, barely edited writeups; I hope they're useful to you too)

Feature flags

This is my own writeup on feature flags; for a deep dive I'd recommend something like Martin Fowler's article (https://martinfowler.com/articles/feature-toggles.html).

So. Feature flags. The basic idea that you'll store configuration/values on a database/service somewhere, and by changing those values, you can change the user experience/features for a user on the fly.

Let's say that you're building a new feature, called 'new-button' which changes the color of buttons, which is currently red, to blue. Then you'd change code that looks like this -

View regions_in_ghana.json
[
{
"name": "Ahafo",
"code": ""
},
{
"name": "Ashanti",
"code": ""
},
{