Skip to content

Instantly share code, notes, and snippets.

View ericedem's full-sized avatar

Eric Edem ericedem

View GitHub Profile
@ericedem
ericedem / relative_file_path.go
Created June 3, 2022 19:50
Golang relative file path
package lib
import (
"path"
"runtime"
)
// GetRelativeFilePath takes the path to the calling source file and appends the provided relative path.
// The path manipulation is for convenience as I find myself in testing needing to do a lot of things like
// GetRelativeFilePath("fixtures/test_data.json")
@ericedem
ericedem / gist:21bd5aa094268b89b5e7d79bfc1b7ab8
Last active October 22, 2018 17:20
failing test output.
~/git/slate$ yarn test --fgrep="slate commands by-key replace-node-by-key oneBlock"
yarn run v1.9.4
$ cross-env BABEL_ENV=test FORBID_WARNINGS=true mocha --require babel-core/register ./packages/*/test/index.js '--fgrep=slate commands by-key replace-node-by-key oneBlock'
slate
commands
by-key
replace-node-by-key
1) oneBlock
@ericedem
ericedem / gist:9e51a181689769ae9510fb02428fc1d8
Created October 19, 2018 04:36
delete empty removes paragraph
/** @jsx h */
import h from '../../../helpers/h'
export default function(change) {
change.delete()
}
export const input = (
<value>
/** @jsx h */
import h from 'slate-hyperscript'
export const input = (
<block type="paragraph">
<text />
<inline type="link">Some inline link</inline>
<text />
</block>
@ericedem
ericedem / react_learning.md
Last active September 19, 2018 15:16
React learning resources

ES6:

Before diving into react, I'd recommend getting a fundamental understanding of the latest JS syntax. Most examples out there will be written in the latest style, and most people are using transpilers to be able to write the latest code.

  • I don't have a good specific resource for this, but Dr. Axel has some good in depth stuff about it: http://dr-axel.de/
  • Destructuring and default parameters are probably some of the most used new features.

React:

@ericedem
ericedem / rule.js
Created August 7, 2018 14:12
Difference between declared rule and internal representation
// Declared output
const schema = {
document: {
nodes: [
{ match: { type: 'title' }, min: 1, max: 1 },
{ match: { type: 'paragraph' }, min: 1 },
],
normalize: (change, { code, node, child, index }) => {
// This doesn't do anything and will never fix the validation errors.
},
@ericedem
ericedem / gist:6db39a769cd5bfb691a759c7e2798559
Created February 26, 2018 18:15
Downshift blocks enter
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Downshift from 'downshift';
let items = ['a', 'ab', 'abc'];
class Widget extends Component {
render () {
return (
<form onSubmit={e => {
def split_sequential(list):
iterints = iter(list)
result = []
sequence = [next(iterints)]
for i in iterints:
if sequence[-1] + 1 == i:
sequence.append(i)
else: