Skip to content

Instantly share code, notes, and snippets.

import React from 'react'
import NavLink from './NavLink'
import Repo from './Repo'
export default React.createClass({
propTypes: {
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.instanceOf(Repo)),
React.PropTypes.instanceOf(Repo)
])
@onionmk2
onionmk2 / react_tutorial_client.jsx
Created September 14, 2016 14:30
react_tutorial_client.jsx
const DOMPurify = require('dompurify');
const React = require('react');
const ReactDOM = require('react-dom');
const Remarkable = require('remarkable');
const Comment = React.createClass({
propTypes: {
author: React.PropTypes.string.isRequired,
children: React.PropTypes.string.isRequired,
},
@onionmk2
onionmk2 / react_tutorial_server.js
Created September 14, 2016 14:31
react_tutorial_server.js
const Http = require('http');
const Url = require('url');
const Path = require('path');
const Fs = require('fs');
const COMMENTS_FILE = 'comments.json';
const server = Http.createServer(function requestListener(inComingMessage, serverResponse) {
console.log(inComingMessage.method, inComingMessage.url, `at ${new Date()}`);
console.log(inComingMessage.headers);
@function str-replace($string, $search, $replace: '') {
$index: str-index($string, $search);
@if $index {
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
}
@return $string;
}
@onionmk2
onionmk2 / trip.ts
Created November 19, 2016 10:11
分岐を多態で置き換える
class Trip {
destination: string;
startDate: Date;
constructor(destination, startDate) {
this.destination = destination;
this.startDate = startDate;
}
prepare(preparers) {
@onionmk2
onionmk2 / tsconfig.json
Created November 30, 2016 14:49
reactでの tsconfig.json 一例
{
"compilerOptions": {
"outDir": "./dist/",
"module": "commonjs",
"target": "es5",
"noImplicitAny": true,
"inlineSourceMap": true,
"experimentalDecorators": true,
"jsx": "react",
"pretty": true,
@onionmk2
onionmk2 / functionType.ts
Last active December 4, 2016 05:57
TypeScriptの関数の型
/*
#1 関数宣言
function funcName() : returnType => {}
*/
function funcName (x) {}
function funcNameTs(x: number): number { return x;}
/*
#2 関数式
*/
@onionmk2
onionmk2 / gist:895879d0a6a2fe2b6ec28b636fc809cc
Last active December 6, 2016 14:42
prototypeにはえてるプロパティをenumrableなものも取りたいときの方法
let fs = require('fs');
function log(targat) {
const target = targat.prototype;
const fileName = __dirname + '/dist/' + target.constructor.name + '.txt';
const props = Object.getOwnPropertyDescriptors(target);
const str = Object.keys(props).join('\n');
fs.createWriteStream(fileName).write(str);
}
@onionmk2
onionmk2 / memo.md
Last active December 10, 2016 02:15
typescript環境の備忘録
/*
TSのインターフェースとは 以下2つのうちのいずれか。
1. 抽象的な型。 プロパティの名前・型を指定した、JSオブジェクト。
2. 引数と戻り値の型を明示した、Functionオブジェクト。
http://stackoverflow.com/questions/41082804/does-typescript-interface-have-anonymous-and-named-function/41082880#41082880
*/
// 1. JSオブジェクト