Skip to content

Instantly share code, notes, and snippets.

View snipsnipsnip's full-sized avatar

Satoshi Kodama snipsnipsnip

View GitHub Profile
@snipsnipsnip
snipsnipsnip / ko.extenders.wrapNumber.js
Last active January 3, 2016 01:29
ko.extenders.wrapNumber is a knockout.js extension that forces an number observable to be wrapped around the specified inclusive range
/**
* Forces an number observable to be wrapped around the specified inclusive range [min, max].
* If specified, options.onWrap will be called back when the 'wrapping' occurs
* (i.e. the write attempt of the value out of the range).
* options.onWrap will be called with an argument false on underflow, or true on overflow.
*
* @param {ko.observable} target
* @param {{min: number, max: number, onWrap: ?function(boolean), onWrapOwner: ?*}} options
* @return {ko.computed} wrapped target
*/
@snipsnipsnip
snipsnipsnip / flatgas.coffee
Created December 23, 2013 22:13
gas-managerが柔軟すぎて馴染めなかったのでmanager部分だけ取り出してバグチェックとか取っ払ってコマンドインタフェースをコピペしながら再発明した 結構注意点が多くてつらい
fs = require 'fs'
path = require 'path'
async = require 'async'
commander = require 'commander'
gas_manager = require 'gas-manager'
request = require 'request'
util = require 'gas-manager/out/lib/commands/util'
main = ->
commander
@snipsnipsnip
snipsnipsnip / rewrite-author.sh
Created December 23, 2013 20:53
a commit filter for a git-svn'd repository (maps author and removes git-svn id but revision number)
git filter-branch --commit-filter '
case "$GIT_AUTHOR_NAME" in
*suzuki*)
GIT_AUTHOR_NAME="suzu"
GIT_AUTHOR_EMAIL="suzu@example.com"
;;
*)
GIT_AUTHOR_NAME="someone"
GIT_AUTHOR_EMAIL="someone@example.com"
;;
@snipsnipsnip
snipsnipsnip / dollar-expr.scm
Last active December 29, 2015 05:09
$-expression for gauche
(define-module $exp-convert
(use srfi-1)
(use util.match)
(export
$exp-list->sexp)
;;; port->$exp-listで読まれたものをS式に変換する。
(define ($exp-list->sexp $exp)
($ reverse
@snipsnipsnip
snipsnipsnip / nyaos_filter_quote_eval.lua
Created October 9, 2013 02:50
nyaos.filter.quote_eval: bash-like $() style quote for nyaos
-- nyaos_filter_quote_eval.lua
-- bash風な逆クォートのカッコ版。ネスト可能。
-- 「echo $(echo bar $(echo foo))」は「bar foo」と出力される。
function nyaos.filter.quote_eval(cmdline)
return cmdline:gsub('%$(%b())', function(m)
local result, err = nyaos.eval(string.sub(m, 2, -2))
if err then
print('error in substitution: '..err)
return false
@snipsnipsnip
snipsnipsnip / convert-from-jabberbook-xml-to-disqus-wxr.rb
Created September 21, 2013 10:38
Dump Jibberbook's comments.xml as Disqus importable WXR
#!/usr/bin/ruby-1.9
require 'nokogiri'
# cf. http://help.disqus.com/customer/portal/articles/472150
def tag(n,c='') "<#{n}>#{c}</#{n}>" end
def t(n,c='') print tag(n, c) end
doc = File.open("comments.xml", encoding:'utf-8'){|f| Nokogiri::XML f }
@snipsnipsnip
snipsnipsnip / news.rb
Last active December 21, 2015 06:09
news.rb
require 'weakref'
# ニュース。グローバルpubsub。
#
# News.newsで発信。こんなふうに書く。
#
# 誰かの誕生日があったことを発信する。
#
# def tick
# News.news(:birthday) if @month == 10 && @day == 5
@snipsnipsnip
snipsnipsnip / n-back.rb
Created August 16, 2013 18:28
n-back.rb (脳トレの記憶計算ゲームやっつけ)
=begin
made with dotgame: https://gist.github.com/962107
参考: http://www.nintendo.co.jp/3ds/asrj/movie/movie.html?mov=3back
nバックは20+2n問出るのかな
nバックでは、m番目の問題を見ながら(n-m)番目の問題に答える
問題は上から流れてくる
each_consみたいな具合
@snipsnipsnip
snipsnipsnip / pushd-shortcut.bat
Last active December 20, 2015 09:59
pushd-shortcut.bat: ショートカットの飛び先を読み取ってそこまでpushdする
@if exist "%~f1" @(
echo pushd "%~f1"
pushd "%~f1"
) else @for %%i in (%1.lnk) do @(
for /f %%n in ('perl -x "%~f0" %%~$path:i') do @(
echo pushd %%n
pushd %%n
)
)
@exit /b
@snipsnipsnip
snipsnipsnip / bullet.hpp
Last active December 17, 2015 08:49
A single-class btDiscreteDynamicsWorld wrapper
#ifndef INCLUDED_BULLET_HPP_
#define INCLUDED_BULLET_HPP_
#include "btBulletDynamicsCommon.h"
namespace bullet_wrapper {
// 使うクラスの目次がわりのtypedef
typedef btDiscreteDynamicsWorld World;