Skip to content

Instantly share code, notes, and snippets.

View cognitom's full-sized avatar

Tsutomu Kawamura cognitom

View GitHub Profile
@cognitom
cognitom / keymap.c
Last active January 11, 2023 02:36
Lock key indicator with RGB matrix on QMK
// keymap setting and etc...
// store the state
static bool _is_key_locked = false;
void keyboard_post_init_user(void) {
// need to stop effects and animations
rgb_matrix_mode(RGB_MATRIX_NONE);
rgb_matrix_sethsv(HSV_OFF);
}
@cognitom
cognitom / group-name.sh
Created September 18, 2021 01:56
In some cases, I got to get the user/group's name from its id. Here's how-to.
# 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 January 17, 2019 14:08 — forked from ytomino/romantable_jisx6004.txt
JIS-X-6004 for Google日本語入力
- -
~ 〜
〜~ ~
. 。
, 、
[ ち
] 」
{ 「
} 」
・. …
@cognitom
cognitom / quickstart.js
Last active October 29, 2020 23:09
Unspaghetti version of Google Spreadsheet API example code
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 January 30, 2017 02:13
openBDの日付フィールドのノーマライズ
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 January 7, 2023 07:34
openBDの全データを整形しつつ単一ファイルにダウンロード
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 July 3, 2016 05:54
How to use postcss with Riot.js
<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 June 29, 2016 03:39
How to get [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] in JavaScript
// 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
/* 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 March 31, 2015 04:25
Underscore2Hyphen
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)_(.*) $1-$2 [N=10,DPI]
RewriteRule (.*) http://somewhere.dom/$1 [R=301]
</IfModule>