Skip to content

Instantly share code, notes, and snippets.

@higuma
higuma / ArrayPermutation.coffee
Last active December 18, 2015 13:02
CoffeeScript Array permutation generator
# internal: generate permutation recursively
generatePermutation = (perm, pre, post, n) ->
if n > 0
for i in [0...post.length]
rest = post.slice 0
elem = rest.splice i, 1
generatePermutation perm, pre.concat(elem), rest, n - 1
else
perm.push pre
return
@higuma
higuma / ArrayPermutation.js
Last active September 8, 2023 10:15
JavaScript Array permutation generator
// JavaScript Array permutation generator
// (optimized from CoffeeScript output: see ArrayPermutation.coffee)
(function() {
var generatePermutation = function(perm, pre, post, n) {
var elem, i, rest, len;
if (n > 0)
for (i = 0, len = post.length; i < len; ++i) {
rest = post.slice(0);
elem = rest.splice(i, 1);
generatePermutation(perm, pre.concat(elem), rest, n - 1);
@higuma
higuma / config.ru
Created April 1, 2014 10:40
開発用ローカルサーバを立ち上げる方法 ref: http://qiita.com/higuma/items/b23ca9d96dac49999ab9
run Rack::Directory.new '.'
@higuma
higuma / Gemfile
Created April 4, 2014 13:57
HerokuにRackでdeployする(初級編:静的HTMLページ) ref: http://qiita.com/higuma/items/9baac9e97eeb862ef64e
source 'https://rubygems.org'
ruby 2.0.0
gem 'rack'
@higuma
higuma / file0.coffee
Created April 5, 2014 06:18
CoffeeScriptワンポイント - 値を返さない関数にはreturnを付ける ref: http://qiita.com/higuma/items/ff329775f3a91a6c6fb3
a = for x in [0..5]
x * x
console.log a # => [ 0, 1, 4, 9, 16, 25 ]
b = while a.length > 0
a.pop()
console.log b # => [ 25, 16, 9, 4, 1, 0 ]
@higuma
higuma / alphametics.rb
Created April 8, 2014 11:08
覆面算を解く(Ruby/Pythonレクリエーション) ref: http://qiita.com/higuma/items/c44246ebd8e6e4a14a64
require 'set'
require 'mathn'
module Alphametics
def solve(puzzle)
puzzle = puzzle.upcase
words = puzzle.scan /[A-Z]+/
chars = Set.new words.join.each_char
abort 'Too many letters' if chars.size > 10
first_chars = Set.new words.select {|w| w.size > 1 }.map {|w| w[0] }
This is *emphasized*
@higuma
higuma / config.ru
Created April 13, 2014 12:01
Rack解説 - Rackの構造とRack DSL ref: http://qiita.com/higuma/items/838f4f58bc4a0645950a
use Rack::ETag
use Rack::Deflater
use Rack::Static, urls: [''], root: 'public', index: 'index.html'
run lambda {|env|} # run proc {|env|} も可
@higuma
higuma / file0.txt
Created April 27, 2014 10:32
Rack応用 - HTTP圧縮エンコーディング最適化 ref: http://qiita.com/higuma/items/9b841aca5f3d58a2b5aa
Accept-Encoding: gzip, deflate
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>