This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function times(n) { | |
const iterator = (function* gen(n) { | |
let count = 0; | |
while (count < n) { | |
yield count; | |
count++; | |
} | |
})(n); | |
return Array.from(iterator); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM UNNEST(ARRAY<STRUCT<`name` string, `group` string, age INT64>>[ | |
('a', 'A', 10),('b', 'A', 11),('c', 'A', 12), | |
('f', 'B', 20),('e', 'B', 10),('d', 'B', 11) | |
]) | |
) | |
SELECT `group`, `age`, COUNT(DISTINCT `name`) | |
FROM t | |
GROUP BY ROLLUP(1, 2) | |
ORDER BY 1, 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'with_resources/toplevel' | |
using WithResources::TopLevel | |
resources = -> () { | |
hello = StringIO.new('Hello') | |
world = StringIO.new('World') | |
} | |
with(resources) do |hello, world| | |
puts "#{hello.gets}, #{world.gets}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tapp' | |
def main(str) | |
x, y, b = str.split(',').map(&:to_i) | |
x_size = x.to_s(b).size | |
min = if x_size.odd? | |
(1..((b-1).to_s*(x_size / 2 + 1)).to_i(b)).flat_map { |n| check(n, b) }.uniq.select { |_n| _n < x }.size | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# columns example | |
# [ | |
# ['hoge total', 'hoge'], | |
# ['fuga total', 'fuga'], | |
# ['piyo total', 'piyo'], | |
# ] | |
def cube_select_expressions(columns) | |
[true, false].repeated_permutation(columns.size).map { |flags| | |
flags.zip(columns).map { |flag, (total_label, column_name)| | |
flag ? column_name : "'#{total_label}' AS #{column_name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(str) | |
n = str.to_i | |
n3 = '0' + n.to_s(3) | |
nums = case n3 | |
when /0$/ | |
[ | |
n3.sub(/20+$/) { |m| '0' + '2' * (m.size - 1) }.to_i(3), | |
n3.sub(/10+$/) { |m| '0' + '1' * (m.size - 1) }.to_i(3), | |
n + 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable, Subject } from 'rxjs'; | |
const subj = new Subject(); | |
subj.take(10). | |
startWith([1, 1]). | |
scan(([a, b], _) => [b, a + b]). | |
do(([a, b]) => console.log(a)). | |
subscribe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Observable } = require('rxjs'); | |
const streams = Array(10).fill(null).map(_ => { | |
const f = Math.random(); | |
console.log(f); | |
return Observable.of(f).delay(f * 100); | |
}) | |
Observable. | |
race(...streams). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Observable } = require('rxjs'); | |
const n$ = new Observable.range(0, 100); | |
const fizz$ = n$.map(n => n % 3 == 0 ? 'Fizz' : ''); | |
const buzz$ = n$.map(n => n % 5 == 0 ? 'Buzz' : ''); | |
Observable. | |
zip(n$, fizz$, buzz$). | |
map(([n, fizz, buzz]) => fizz + buzz || n). | |
do(console.log). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Observable } = require('rxjs'); | |
new Observable.range(0, 100). | |
map(n => [n]). | |
map(a => a.concat([a[0]%3 == 0 ? 'Fizz' : ''])). | |
map(a => a.concat([a[0]%5 == 0 ? 'Buzz' : ''])). | |
map(([n, fizz, buzz]) => fizz + buzz || n). | |
do(console.log). | |
subscribe(); |