Skip to content

Instantly share code, notes, and snippets.

@masahirompp
masahirompp / menu.jsx
Created August 1, 2015 10:45
menu.jsx
// menu.jsx
var m = require('mithril');
function view(ctrl) {
function redirect(e) {
e.preventDefault();
m.route(e.target.getAttribute('href'));
}
@masahirompp
masahirompp / Makefile
Last active August 29, 2015 14:17
makefile
BIN = ./node_modules/.bin
build: install typings
$(BIN)/webpack
watch: install typings
$(BIN)/webpack --watch
install:
@npm install
@masahirompp
masahirompp / controller.js
Created February 21, 2015 12:09
javascript mvc (no framework) http://jsfiddle.net/54sjqL6z/
(function(todo) {
'use strict';
// viewの追加イベントを監視。TodoListに新規Todoを追加する。
todo.View.on('add', function(description) {
todo.TodoList.add(new todo.Todo(todo.TodoList.length, description));
todo.View.clearInput();
});
// viewの変更イベントを監視。モデルの状態を更新を命令。
@masahirompp
masahirompp / module1.js
Last active August 29, 2015 14:15
AMD/namespace template
(function(factory){
if(typeof define === 'function' && define.amd){
define(['underscore', 'other1'], factory.bind(this));
}else{
this.module1 = factory.call(this, this._, this.other1);
}
}.call(this, function(_, other1){
'use strict';
// ここに処理を書く
}));
/// <reference path="../../../tsd/underscore/underscore.d.ts" />
/**
*
* @param thing
*/
function fail(thing) {
throw new Error(thing);
}
@masahirompp
masahirompp / fun.js
Created February 4, 2015 15:27
utils
'use strict';
var _ = window._;
/**
*
* @param thing
*/
function fail(thing) {
throw new Error(thing);
@masahirompp
masahirompp / User.ts
Last active May 5, 2021 20:04
mongoose + typescript
/// <reference path="../tsd/tsd.d.ts" />
import mongoose = require('mongoose');
import passport = require('passport');
interface IUser extends mongoose.Document {
provider: string;
id: string;
authorId: string;
displayName: string;
@masahirompp
masahirompp / Author.ts
Last active February 25, 2021 11:14
typescript + mongoose
/// <reference path="../typings/tsd.d.ts" />
import db = require('../db/db');
import IAuthorDocument = require('../db/IAuthorDocument');
class Author {
private _author:IAuthorDocument;
constructor(author:IAuthorDocument) {
this._author = author;