Skip to content

Instantly share code, notes, and snippets.

Avatar

Valery iofjuupasli

View GitHub Profile
@iofjuupasli
iofjuupasli / oEmbed.js
Created Oct 29, 2019
Simplest oEmbed iframe implementation
View oEmbed.js
const express = require(`express`);
const router = express.Router();
router.get(`/oembed`, (req, res) => {
const {url, maxwidth, maxheight, format} = req.query;
const width = maxwidth || 1000;
const height = maxheight || 600;
const embedUrl = url; // you can transform url that user provided to url that should be displayed in iframe
const responseData = {
View rr.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
a
0.00001
123.123123
0.10001
0.00011
0.1111111
323.0001
4
5422
@iofjuupasli
iofjuupasli / convert.js
Last active Sep 22, 2017
Lodash fp autocurry
View convert.js
const readline = require(`readline`);
const fs = require(`fs`);
const rl = readline.createInterface({
input: fs.createReadStream(`./to_parse_v4.x.x.js`),
});
const getArgs = /((\(\([^\)]*\)[^\)]*\))|[\w?]|(: )|(\<[^\>]*\>)|(\([^\)]*\))|( => )|( \| )|(\{[^\}]*\})|(\[[^\]]*\])|[\<\>]|( \& ))+/g;
const split = (line) => {
View rdma.js
myData.map(fixName);
function fixName(person) {
return Object.assign({}, person, {
name: person.name.replace(/John/g, "Ben")
});
}
// inline function
myData.map(function fixName(person) {
View hyperscript-style-guide.js
// All children from new line
// bad
h('.my-class', null, h('span', null, 'Foo'));
// good
h('.my-class', null,
h('span', null,
'Foo'
)
);
View jsxvsjs-br.jsx
return <div>
<header className="header">
<h1>todos</h1>
<input
className="new-todo"
placeholder="What needs to be done?"
value={this.state.newTodo}
onKeyDown={this.handleNewTodoKeyDown(todo)}
onChange={this.handleChange(e)}
autoFocus=true
View jsxvsjs-eq.jsx
// A
<li className={classNames({
completed: this.props.todo.completed,
editing: this.props.editing
})}>
// B
<input
className="toggle"
type="checkbox"
View todoItem.js
return h('li', {
className: classNames({
completed: this.props.todo.completed,
editing: this.props.editing
})
},
h('div.view', null,
h('input.toggle', {
type: 'checkbox',
checked: this.props.todo.completed,
View todoItem.jsx
return (
<li className={classNames({
completed: this.props.todo.completed,
editing: this.props.editing
})}>
<div className="view">
<input
className="toggle"
type="checkbox"
checked={this.props.todo.completed}
You can’t perform that action at this time.