Skip to content

Instantly share code, notes, and snippets.

export function preventDefault (func, ...args) {
return e => {
e.preventDefault()
func(...args)
}
}
export function targetValue (func, ...args) {
return e => {
func(e.target.value, ...args)
@masahirompp
masahirompp / ImageUtils.ts
Last active October 8, 2017 04:59
image file to DataUri, DataUri(or image src) to ImageData
export function imageFileToDataUri (file: File) {
return new Promise<string>(done => {
const reader = new FileReader()
reader.onloadend = () => done(reader.result)
reader.readAsDataURL(file)
})
}
export function imageSrcToImageData (imageSrc: string) {
return new Promise<ImageData>(resolve => {
@masahirompp
masahirompp / react-svg-pan-zoom.d.ts
Created February 25, 2017 14:14
react-svg-pan-zoom.d.ts
declare module 'react-svg-pan-zoom' {
import * as React from 'react'
type Tool = 'auto' | 'none' | 'pan' | 'zoom-in' | 'zoom-out'
type ToolBarPosition = 'none' | 'top' | 'right' | 'bottom' | 'left'
export const ReactSVGPanZoom: ReactSVGPanZoom
interface ReactSVGPanZoom extends React.ComponentClass<ReactSVGPanZoomProps> {}
@masahirompp
masahirompp / react-dnd-touch-backend.d.ts
Created February 25, 2017 14:13
react-dnd-touch-backend.d.ts
declare module 'react-dnd-touch-backend' {
import { Backend } from 'react-dnd'
declare const Backend: Backend
export default Backend
}
@masahirompp
masahirompp / react-dimensions.d.ts
Created February 25, 2017 14:13
react-dimensions.d.ts
declare module 'react-dimensions' {
import * as React from 'react'
interface Dimensions {
<P extends React.Props<any>>(options?: Options): (component: React.ComponentClass<P>) => React.ComponentClass<P>
}
declare const Dimensions: Dimensions
export default Dimensions
@masahirompp
masahirompp / stylus compile
Last active March 8, 2017 02:29
stylus compile
stylus --sourcemap --use ./node_modules/axis --out build app/index.styl
@masahirompp
masahirompp / jwt.js
Created February 13, 2016 17:05
json web token encode / decode sample.
import * as _ from 'underscore';
import * as moment from 'moment';
import * as jwt from 'jwt-simple';
import * as config from 'config';
import * as Log from './Log';
/**
* エンコードする
* 有効期限を付与する
* @param data
@masahirompp
masahirompp / Cookie.ts
Created February 13, 2016 17:00
simple cookie util.
@masahirompp
masahirompp / radios.ts
Created February 13, 2016 16:55
mithril(msx) radio button sample.
/**
* ラジオボタンを生成する
* @param {[type]} args: {value: string; label: string }[] [description]
* @param {[type]} name: string [description]
* @param {[type]} currentValue: string [description]
* @param {[type]} callback: (value:string)=>void [description]
* @return {[type]} [description]
*/
export function radios(args: { value: string; label: string }[], name: string, currentValue: string, callback: (value: string) => void) {
if (args.length === 0) {
<div class="select">
<select>
<option value="a">AAA</option>
<option value="b">BBB</option>
<option value="c">CCC</option>
</select>
</div>