Entries from 2017-01-01 to 1 year

ブロック要素にリンク(a tag)をつける

ブロック要素内のaタグを、要素いっぱいに広げる text-indent: -999px; などでテキストを非表示にする必要がある シンプルにaタグでブロック要素を包む ブロック要素内のテキストがリンクテキストと同じスタイルにならないように調整する(必要ならば) a { …

複数行をTruncate

css

ブラウザが限られている(Safari, Chrome) そのうち使えなくなるかもしれない heightで制限しているので、対象ブラウザ以外でもレイアウトが崩れることはない、はず .note { font-size: 16px; line-height: 1.25; width: 100px; border: 1px solid #000; over…

ユーザーからのフィードバックをSlackで受け取る

こういうやつを作りました。 Node.js用のSlack SDKを利用したら簡単にできました。 GitHub - slackapi/node-slack-sdk: Slack Developer Kit for Node.js 以下、Webhook URL発行前提の話です。 const IncomingWebhook = require('@slack/client').IncomingWe…

カラーコードの変換 (Hex -> RGB)

例えば#ff0000をrgb(255,0,0)に変換したい場合。 カラーコード(文字列)を2文字ずつに分ける 16進法を10進法に変換する import compose from 'lodash/fp/compose'; import map from 'lodash/fp/map'; function hexToRgb(hex: string): string { return comp…

null vs undefined

undefinedを使うべきかnullを使うべきか。コンテキストで使い分けるべきか。 Coding guidelines · Microsoft/TypeScript Wiki · GitHub contributors向けのガイド。undefinedを使えとのこと。 Rule: no-null-keyword TSLintにルールもある。

MouseEvent, KeyboardEventを利用してHTMLElementを操作

Event - Web APIs | MDN MouseEvent - Web APIs | MDN KeyboardEvent - Web APIs | MDN HTMLElement - Web APIs | MDN EventTarget <- Node <- Element <- HTMLElement /** * ボタンのdisabled属性を変更 */ public onMouseEvent($event: MouseEvent) { cons…

NgModulesのドキュメント読む

前回のスタイルガイドに続き、ドキュメント読んで気になる箇所を抜粋。 NgModules Angular modularity The root AppModule Bootstrapping in main.ts Declare directives and components Service providers Import supporting modules Application-scoped pr…

Angular4スタイルガイド読む

Angular公式のStyle Guideから気になった箇所を抜粋したものです。 Style GuideとNgModulesについての公式ドキュメントを読んだら、実際のアプリを作るときの大枠がある程度整理できました。 ドキュメントはそれなりに長いですが、命名規則など、Angular CLI…

Angular4さわる

これは何か 前提知識 調べたことメモ Angular CLI Autoprefixer 環境変数 IE9, IE10, IE11対応 ビルド SCSS VS Codeエクステンション よかったチュートリアル これは何か 新機能開発をAngular4で作り始めました。その時に調べたことのメモです。 Angular CLI…

画像を内接リサイズにする

css

css - Resize to fit image in div, and center horizontally and vertically - Stack Overflow transformとposition: absoluteを利用します。 前の記事のアスペクト比を保つcssを利用するとこんな感じです。 object-fitというプロパティを利用すればもっと…

アスペクト比を保つ

css

「padding-topに%を設定すると、包括しているブロックの幅を基準にする」という仕様を利用します。 padding-top - CSS | MDN 以下のコードは、アスペクト比を4:3にする場合。 .a43 { border: 1px solid #000; width: 160px; position: relative; } .a43:befo…

AngularでBugsnagを利用

Angular4始めました。 Angularでエラーをインターセプトする場合はこんな感じ。 import { ErrorHandler, Injectable} from '@angular/core'; import { environment } from '../environments/environment'; @Injectable() export class GlobalErrorHandler im…

VS Codeでタイトルバーの色変更

複数のプロジェクトやライブラリをみる場合に便利。 画像の例は、自分の仕事とAngularとBootstrap4を開いている場合。 // Place your settings in this file to overwrite default and user settings. { "workbench.colorCustomizations": { "titleBar.activ…

JavaScript (TypeScript) クラス、型の判定

class Foo {} class Bar extends Foo {} const foo = new Foo(); const bar = new Bar(); console.log(typeof foo); // -> 'object' console.log(foo.constructor === Foo); // -> true console.log(foo instanceof Foo); // -> true console.log(foo instan…

word-break, overflow-wrap, word-wrap

word-break - CSS | MDN overflow-wrap - CSS | MDN

これをこうした (Viewのリファクタ)

命名、フォルダ構造、Viewと機能(性質)をごっちゃにしないのは大切ですよ、という反省。 フォルダ構造 ├── components │ ├── baz │ │ ├── abstract │ │ ├── a │ │ └── b │ ├── bazes-container │ ├── main │ │ └── bg │ ├── qux │ │ ├── abstract │ │ ├── …

Hubotを使ってGoogle AnalyticsのデータをSlackに流す

1年ほど前にまとめたものです。 環境準備 起動 Herokuで動かす HUBOT_HEROKU_KEEPALIVE_URL Google Analyticsの情報を取得 Google Developersの設定 1. APIを有効にする 2. サービス アカウント キーを作成する 認証 補足: Scopeについて Analyticsの設定 1.…

z-indexとスタック文脈

重なり順の制御をしているときに、スタック文脈というものを理解していなかったことに気づきました。 以下の記事がわかりやすかったです。MDNにはいつもお世話になります。ありがたい。 CSS の z-index の理解 - CSS | MDN z-index なしのスタック : デフォ…

(WIP) Pub-Sub

(1年前に途中までまとめたもの。こっちに転載。) AngularJS: Notifying about changes from services to controllers - codelord.net を参考にStoreっぽいものを実装しようとした時のメモ // component class FooController { constructor( private $scope…

マルチバイト文字, fromCharCode, charCodeAt, Unicode

マルチバイト文字かどうか確認 /** * UTF-8における、1Byte以外の文字かどうか * -> 0-127 (ASCII 文字セット) 以外 */ function hasMultibyte(str) { return /[^\u0000-\u007f]/.test(str); } hasMultibyte('a'); // -> false hasMultibyte('>'); // -> fal…

(WIP) Cloud Node.js Clientを利用してBigQueryのクエリ結果を取得

0. 動機 BigQueryの実行結果を整形・表示・チャート化しやすい環境をつくる ほぼ自分用 1. Nodeからクエリを実行 GitHub - GoogleCloudPlatform/google-cloud-node: Google Cloud Client Library for Node.js 準備 npm install --save @google-cloud/bigquer…

TypeScriptでJSONファイルをimportする

webpack2利用時。 custom-typings.d.ts declare module '*.json' { const value: any; export default value; } foo.ts import * as data from './data.json'; // ... Support shorthand ambient module declarations and wildcard chars in module names · …

通貨記号つきで金額を表示

便利。(最近まで知らなかった) IEは11以上なら大丈夫。 console.log(number.toLocaleString('ja-JP', { style: 'currency', currency: 'JPY' })) // → ¥123,457 console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).for…

ng-tableさわる

http://ng-table.com/ 準備 webpack×TypeScriptの場合 webpack.config.js module.exports = { // ... module: { rules: [ { test: /\.tsx?$/, loader: 'ts-loader' }, { test: /\.html$/, use: [ { loader: 'ngtemplate-loader', options: { requireAngular:…

three.jsさわる

The Making of "The Aviator": Animating a Basic 3D Scene with Three.js | Codrops ここのチュートリアルが分かり易い&サンプルがかわいい。

クライアント側でCSV生成してダウンロードさせる

追記: Safariも10.1からdownload属性が利用できるにようになりました。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Browser_compatibility CSVの生成 参考 ダウンロード msSaveBlob download属性 Data URI scheme + data:attachment/… サ…

Swiftの勉強(SpriteKit)

GitHub - fullstackio/FlappySwift: swift implementation of flappy bird. More at fullstackedu.com がよかった。ありがたいサンプル。 参考Urls オフィシャルドキュメント SpriteKit | Apple Developer Documentation About SpriteKit SpriteKitまとめ(ゲ…

Angular UI-Router v1さわる

環境は angular-ui-router 1.0.0-rc.1。 v0.3からMigrateした 新機能(uiCanExit, lazyLoadなど)も試したみた ドキュメント読んだ About About - UI-Router Core部分の実装をui-router-coreに分けた AngularJS (1.x), Angular (2.0+), Reactもいける UI-Rou…

webpackさわる

環境は webpack 2.2.1。 コード分割 アプリケーション用のjs (app.js)と、ライブラリをまとめたjs (vendor.js)を分割させたい場合。 webpack.optimize.CommonsChunkPluginを使えばおk オフィシャルドキュメント Code Splitting - Libraries [chunkhash]と[ha…

シェルスクリプトを利用して、tsファイルの先頭にimport文を差し込む

tsファイル内に文字列angularが存在する場合、ファイルの先頭にimport * as angular from 'angular;を追加。 # 改行コード LF=$'\\\x0A' # 結果を配列に files=(`find ./client/{app,components} -type f -name "*.ts" -print0 | xargs -0 grep "angular" -l…