Skip to content

Instantly share code, notes, and snippets.

View srph's full-sized avatar
🛠️
Building @Stride-Labs Frontend

Kier Borromeo srph

🛠️
Building @Stride-Labs Frontend
View GitHub Profile
<base-layout>
<template slot="header">
<h1>Here might be a page title</h1>
</template>
<p>A paragraph for the main content.</p>
<p>And another one.</p>
<template slot="footer">
<p>Here's some contact info</p>
<div class="container">
<header>
<slot name="header"></slot>
</header>
<main>
<slot></slot>
</main>
<footer>
<slot name="footer"></slot>
</footer>
<MyPopover open={this.state.open}
onOpen={this.handleOpen}
onClose={this.handleClose}
renderButton={<button>Click!</button>}>
<h1>My Popover!!</h1>
</MyPopover>
@srph
srph / index.js
Last active May 23, 2018 02:32
JS: Array.from that works without .length
/**
* Converts an array-like object into an array.
* Array.from doesn't work if an object doesn't have a "length" property.
* e.g., Array.from({ 0: 1 }) doesn't work; Array.from({ 0: 1, length: 1 }) does.
*/
function arrayFrom (obj: {}): Array<*> {
return Object.keys(obj).reduce((set: Array, key: string) => {
return [...set, obj[key]]
}, [])
}
@srph
srph / delay.js
Last active May 17, 2018 08:28
Add a delay between each ajax call
export default function delay(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
@srph
srph / f.txt
Last active February 13, 2018 11:05
txt
@srph
srph / index.js
Created February 11, 2018 21:10
Node: Scale images to ideal size
const Jimp = require('jimp')
const path = require('path')
const glob = require('./utils/glob')
const optim = 300
async function main() {
const files = await glob(path.resolve(__dirname, 'imgsrc/*'))
files.forEach(async file => {
@srph
srph / index.js
Created January 26, 2018 21:20
React: Declaratively resolve data
import React, {Children, cloneElement} from 'react'
import T from 'prop-types'
/**
* Delay component from mounting until promise is resolved.
*/
class Resolver extends React.Component {
state = {
resolved: false,
data: null
@srph
srph / index.js
Last active January 26, 2018 21:22
React: Compose HOCs on-the-go without variable assignment (https://github.com/srph/react-hoc-compose)
import React, {cloneElement} from 'react'
/**
* Make it easier to apply HOC to a component
* without having to assign it to a variable
*/
class Compose extends React.Component {
applied = this.props.hoc(this.props.component)
render() {