This file contains 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
# -*- coding: utf-8 -*- | |
class ManagerCreator(object): | |
u"""プリパラマイマネ問題検証用スクリプト""" | |
color = [u'赤', u'橙', u'黄', u'緑', u'水', u'青', u'紫'] | |
animal = [u'熊', u'兎', u'鳥', u'鼠', u'猫'] | |
def get_manager(self, name): | |
uni_code_point = ord(name) |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from django.core.files.uploadedfile import SimpleUploadedFile | |
from StringIO import StringIO | |
from PIL import Image | |
This file contains 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
<?php | |
function mygenerator() { | |
yield 0; | |
yield 1; | |
yield 2; | |
yield 3; | |
} | |
$g = mygenerator(); |
This file contains 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
<?php | |
function fib_gen() { | |
list($a, $b) = [0, 1]; | |
while(true) { | |
yield $a; | |
list($a, $b) = [$b, $a+$b]; | |
} | |
} |
This file contains 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
DROP TABLE IF EXISTS result; | |
DROP TABLE IF EXISTS student; | |
DROP TABLE IF EXISTS subject; | |
CREATE TABLE student( | |
student_id INT NOT NULL, | |
name VARCHAR(256) NOT NULL, | |
prefecture VARCHAR(256) NOT NULL, | |
age INT NOT NULL, | |
PRIMARY KEY(student_id) |
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
def f(x): | |
return x**3 + 2*x**2 + 10*x - 20 | |
def df(x): | |
return 3*x**2 + 4*x + 10 |
This file contains 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
<?php | |
function take($num, $iterable) { | |
$i = 0; | |
foreach($iterable as $key => $val) { | |
if($i >= $num) { | |
break; | |
} else{ | |
$i++; | |
yield $key => $val; |
This file contains 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
object MyStream { | |
def main(args: Array[String]): Unit = { | |
range(1, 10).take(10).print | |
} | |
private[this] def range(start: Int, end: Int): Stream[Int] = { | |
if(start >= end) { | |
Stream.empty | |
} else { |
This file contains 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
object FibGen { | |
def main(args: Array[String]): Unit = { | |
fibGen.take(10).print | |
} | |
private[this] lazy val fibGen: Stream[Int] = 0 #:: 1 #:: fibGen.zip(fibGen.tail).map(n => n._1 + n._2) | |
} |
This file contains 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
scala> (1 to 10000000).filter(_ % 2 == 0).take(5) | |
// Range(1, 2, ...., 10000000) というコレクションを展開した上で | |
// 全てに対して filter などの処理がが行われるためメモリに大きな負担を与え | |
// 最終的に必要なのは前方5つだけなのに全体をなめるので処理にかなり時間がかかる. | |
scala> (1 to 10000000).view.filter(_ % 2 == 0).take(5).force | |
res0: scala.collection.immutable.IndexedSeq[Int] = Vector(5, 10, 15, 20, 25) | |
// filter や take は遅延評価される | |
// force メソッドで正格なコレクションに戻すことができる. |
OlderNewer