Skip to content

Instantly share code, notes, and snippets.

Avatar

Tsutomu Kawamura cognitom

View GitHub Profile
@cognitom
cognitom / group-name.sh
Created Sep 18, 2021
In some cases, I got to get the user/group's name from its id. Here's how-to.
View group-name.sh
# provide some group's id
$gid=1000
# POSIX way
cat /etc/group | grep ":x:$gid:" | cut -d: -f1
# non-POSIX way which also handles LDAP
getent group "$gid" | cut -d: -f1
# Note that we can't use `id` command for this purpose.
@cognitom
cognitom / jisx6004 romantable.txt
Created Jan 17, 2019 — forked from ytomino/romantable_jisx6004.txt
JIS-X-6004 for Google日本語入力
View jisx6004 romantable.txt
- -
~ 〜
〜~ ~
. 。
, 、
[ ち
] 」
{ 「
} 」
・. …
@cognitom
cognitom / quickstart.js
Last active Oct 29, 2020
Unspaghetti version of Google Spreadsheet API example code
View quickstart.js
import {readFile, writeFile, mkdir} from 'mz/fs'
import readline from 'mz/readline'
import promisify from 'es6-promisify'
import google from 'googleapis'
import googleAuth from 'google-auth-library'
import clientSecret from './client_secret.json'
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/sheets.googleapis.com-nodejs-quickstart.json
const SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
@cognitom
cognitom / normalizeDate.js
Created Jan 30, 2017
openBDの日付フィールドのノーマライズ
View normalizeDate.js
function normalizeDate (raw) {
const patterns = [
// 2017-01-30
{re: /^\d{4}-\d{2}-\d{2}($|,)/, f: m => m[0]},
// 2017-01
{re: /^\d{4}-\d{2}($|,)/, f: m => m[0]},
// 2017
{re: /^\d{4}($|,)/, f: m => m[0]},
// 20170130
{re: /^(\d{4})(\d{2})(\d{2})($|,)/, f: m => `${m[1]}-${m[2]}-${m[3]}`},
@cognitom
cognitom / download.js
Last active Oct 24, 2021
openBDの全データを整形しつつ単一ファイルにダウンロード
View download.js
import {join} from 'path'
import {createWriteStream} from 'fs'
import request from 'request'
import {parse, stringify} from 'JSONStream'
import find from 'lodash.get'
import highland from 'highland'
const apiRoot = 'https://api.openbd.jp/v1'
const cwd = process.cwd()
const distFile = join(cwd, 'all.json')
@cognitom
cognitom / app.tag
Last active Jul 3, 2016
How to use postcss with Riot.js
View app.tag
<app>
<h1>Riot</h1>
<p>A React-like user interface micro-library.</p>
<style scoped type="external">
:scope {
display: block;
}
h1 {
border-bottom: 1px solid black;
@cognitom
cognitom / index.js
Created Jun 29, 2016
How to get [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] in JavaScript
View index.js
// ES6
[...Array(10).keys()]
Array(10).map((n, i) => i)
Array.from(Array(10).keys())
Array.from({ length:10 }, (v, i) => i)
// ES5
Array(10).map(function(n, i) { return i })
// Oldies
View riot+compiler.js
/* Riot WIP, @license MIT, (c) 2015 Muut Inc. + contributors */
;(function(window, undefined) {
'use strict'
var riot = { version: 'WIP', settings: {} }
// This globals 'const' helps code size reduction
// for typeof == '' comparisons
var T_STRING = 'string',
@cognitom
cognitom / .htaccess
Created Mar 31, 2015
Underscore2Hyphen
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)_(.*) $1-$2 [N=10,DPI]
RewriteRule (.*) http://somewhere.dom/$1 [R=301]
</IfModule>
@cognitom
cognitom / file0.txt
Last active Aug 29, 2015
CommonJSフレンドリーな、Angularアノテーション ref: http://qiita.com/cognitom/items/c7b4ffcd26f87b66af8a
View file0.txt
// インジェクション方法 A
$injector.invoke(function(serviceA){});