Skip to content

Instantly share code, notes, and snippets.

View cho45's full-sized avatar

Satoh, Hiroh cho45

View GitHub Profile
@cho45
cho45 / sine.js
Created December 12, 2019 02:48
//#!node
const sleep = (n) => new Promise( (resolve) => setTimeout(resolve, n) );
const asciichart = require('asciichart')
const screen = {
clear: function () {
console.log('\x1b[2J');
},
@cho45
cho45 / github-widget.js
Created February 28, 2012 00:00
Expand any github api to HTML.
// Eg.: http://cho45.github.com/tasscss/
(function () {
var scripts = document.getElementsByTagName('script');
var script = scripts[scripts.length-1];
var container = document.createElement('div');
script.parentNode.insertBefore(container, script);
var callback; do {
callback = 'jsonp' + Math.floor(Math.random() * 0xffff);
function formatN (n) {
const unitList = ['y', 'z', 'a', 'f', 'p', 'n', 'u', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
const zeroIndex = 8;
const nn = n.toExponential(2).split(/e/);
let u = Math.floor(+nn[1] / 3) + zeroIndex;
if (u > unitList.length - 1) {
u = unitList.length - 1;
} else
if (u < 0) {
u = 0;
if (typeof uneval != "function") {
uneval = function (o) {
switch (typeof o) {
case "undefined" : return "(void 0)";
case "boolean" : return String(o);
case "number" : return String(o);
case "string" : return '"' + o.replace(/[^a-z]/gi, function (_) { return '\\u' + (0x10000 + _.charCodeAt(0)).toString(16).slice(1) }) + '"';
case "function" : return "(" + o.toString() + ")";
case "object" :
if (o == null) return "null";
@cho45
cho45 / a.js
Created June 10, 2016 06:07
Date.now() vs new Date().getTime()
document.body.textContent = new Date().getTime();

問題・目的

  • 特定のスプレッドシートだけを外から更新したい
  • OAuth は大変めんどうかつ、特定のスプレッドシートのみ権限を与えることができない
  • Google Spread Sheet の XML API が全力で面倒

方法

  1. いじりたいスプレッドシートで [ツール] → [スクリプトエディタ…] を開く (Google ドライブの新規作成から、スクリプトを選んでもいい)
  2. スクリプトエディタに code.gs の内容をはっつける。
#!/usr/bin/xcrun swift
import Cocoa
struct ProgramOption {
var list : Bool = false
var set : String? = nil
var help : Bool = false
}
@cho45
cho45 / parseIRCMessage.js
Created March 3, 2011 03:23
parseIRCMessage.js
function parseIRCMessage (text) {
var fg = 0;
var bg = 0;
var fl = 0;
var ss = text.split(parseIRCMessage.re);
var ret = [];
var state = {};
for (var i = 0, len = ss.length; i < len; i++) {
text = ss[i];
if (!text) continue;
// ==UserScript==
// @name Hatena::Diary: for writing
// @namespace http://lowreal.net/
// @include http://d.hatena.ne.jp/*gihyo/*
// @require https://gist.github.com/3239.txt#createElementFromString
// @require https://gist.github.com/3238.txt#$X
// @require https://github.com/cho45/jsdeferred/raw/master/jsdeferred.userscript.js
// ==/UserScript==
// つかいかた:
//
=pod
Nyan Cat TAP Formatter
1. Save this file into your PERL5LIB
2. Run prove with option like following:
$ prove --formatter NyanCat
http://www.mattsears.com/articles/2011/11/16/nyan-cat-rspec-formatter