Skip to content

Instantly share code, notes, and snippets.

View cognitom's full-sized avatar

Tsutomu Kawamura cognitom

View GitHub Profile
@cognitom
cognitom / gist:1011960
Created June 7, 2011 09:39
電話番号の正規化 (日本版)
String.prototype.cnvPhone = function(defaultPrefix){
var str0 = this, str1, str;
str1 = str0.replace(/[^\d]/g, '');
if (defaultPrefix && /^[^0]/.test(str1)) str1 = defaultPrefix+str1;//0以外で始まる場合、デフォルトの局番を追加
str = str1;
str = str.replace(/^0(9969|9913|9912|9802|9496|8636|8514|8512|8477|8396|8388|8387|7468|5979|5769|4998|4996|4994|4992|1658|1656|1655|1654|1648|1635|1634|1632|1587|1586|1564|1558|1547|1466|1457|1456|1398|1397|1392|1377|1374|1372|1267)(\d)(\d{4})$/, "0$1-$2-$3");//固定電話市外4桁
str = str.replace(/^0(997|996|995|994|993|987|986|985|984|983|982|980|979|978|977|974|973|972|969|968|967|966|965|964|959|957|956|955|954|952|950|949|948|947|946|944|943|942|940|930|920|898|897|896|895|894|893|892|889|887|885|884|883|880|879|877|875|869|868|867|866|865|863|859|858|857|856|855|854|853|852|848|847|846|845|838|837|836|835|834|833|829|827|826|824|823|820|799|798|797|796|795|794|791|790|779|778|776|774|773|772|771|770|768|767|766|765|763|761|749|748|747|746|745|744|743|742|740|739|738|737|736|735|725|721|599|59
@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 / 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 / getfeed.js
Created May 26, 2012 09:24
Retrieve Facebook page feed from jQuery
$(function(){
var fbpage_id = 131130253626713;// change to your facebook page id.
var fbpage_feed = 'https://www.facebook.com/feeds/page.php?format=atom10&id=' + fbpage_id;
var feed_api = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=' + encodeURIComponent(fbpage_feed);
$.getJSON(feed_api + '&callback=?', function(data){
$(data.responseData.feed.entries).each(function(index){
$('ul#update-feed').append($('<li />', {
'data-role': "list-divider"
}).append($('<a />', {
'href': this.link,
@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 / 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 / index.html
Last active May 7, 2020 08:57
Partial Zoom in Mobile Safari
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<style>
body {
margin: 40px 0 0 0;
padding: 0;
@cognitom
cognitom / split.coffee
Created March 11, 2012 07:37
Cross-browser split function for CoffeeScript
# Cross-Browser Split 1.0.1 for CoffeeScript
# (c) Tsutomu Kawamura @OSSCafe; just converting to CoffeeScript
# (c) Steven Levithan <stevenlevithan.com>; MIT License
# An ECMA-compliant, uniform cross-browser split method */
if !cbSplit
cbSplit = (str, separator, limit) ->
# if `separator` is not a regex, use the native `split`
return cbSplit._nativeSplit.call str, separator, limit if Object::toString.call(separator) isnt "[object RegExp]"
@cognitom
cognitom / jisx6004 romantable.txt
Created January 17, 2019 14:08 — forked from ytomino/romantable_jisx6004.txt
JIS-X-6004 for Google日本語入力
- -
~ 〜
〜~ ~
. 。
, 、
[ ち
] 」
{ 「
} 」
・. …
@cognitom
cognitom / fb2ical.php
Created May 29, 2011 17:36
Export ical format for Facebook page's events
<?php
// https://github.com/facebook/php-sdk/
require_once 'path/to/facebook.php';
// http://www.kigkonsult.se/iCalcreator/
require_once 'path/to/iCalcreator.class.php';
$config = array(
'appId' => 'xxxx',//change to your fb app id
'secret' => 'yyyy',//change to your fb app secret
'pageId' => 'shimokitazawa.osscafe',//change to target fb page id