全然理解出来てなかったので調べてみた。
function f () {
// Class
}| #!/usr/bin/env ruby -wKU | |
| # -*- encoding:utf-8 -*- | |
| class Node | |
| attr_accessor :id, :edges, :cost, :done, :from | |
| def initialize(id, edges=[], cost=nil, done=false) | |
| @id, @edges, @cost, @done = id, edges, cost, done | |
| end | |
| end |
| #!/usr/bin/ruby | |
| require "optparse" | |
| mode = :help | |
| opt = OptionParser.new | |
| opt.on("-a", "Add BOM"){|v| mode = :add} | |
| opt.on("-d", "Delete BOM"){|v| mode = :delete} | |
| opt.parse!(ARGV) |
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |
| <?php | |
| // requires php5 | |
| define('UPLOAD_DIR', 'images/'); | |
| $img = $_POST['img']; | |
| $img = str_replace('data:image/png;base64,', '', $img); | |
| $img = str_replace(' ', '+', $img); | |
| $data = base64_decode($img); | |
| $file = UPLOAD_DIR . uniqid() . '.png'; | |
| $success = file_put_contents($file, $data); |
| <?php | |
| class Struct | |
| { | |
| /** | |
| * Define a new struct object, a blueprint object with only empty properties. | |
| */ | |
| public static function factory() | |
| { | |
| $struct = new self; | |
| foreach (func_get_args() as $value) { |
| <?php | |
| set_include_path('/path/to/pear' . PATH_SEPARATOR . get_include_path()); | |
| spl_autoload_register(function($className) { | |
| if (false !== ($path = stream_resolve_include_path( | |
| str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php')) | |
| ) { | |
| return include $path; | |
| } | |
| return false; |
| # | |
| # Perlのオブジェクト指向なコードを書いてみる | |
| # http://codepad.org/z5axBdJP | |
| # | |
| use strict; | |
| use warnings; | |
| # 名前空間(パッケージ)の宣言。 | |
| # すべてのパッケージは暗黙のルートパッケージ main に属する。 | |
| package PerlOop; |
| package me.rerun; | |
| public class Kadane { | |
| public static void main(String[] args) { | |
| int[] intArr={3, -1, -1, -1, -1, -1, 2, 0, 0, 0 }; | |
| //int[] intArr = {-1, 3, -5, 4, 6, -1, 2, -7, 13, -3}; | |
| //int[] intArr={-6,-2,-3,-4,-1,-5,-5}; | |
| findMaxSubArray(intArr); | |
| } |
| var url = 'http://static1.kevincennis.com/sounds/callmemaybe.mp3' | |
| , audio = new Audio(url) | |
| , context = new webkitAudioContext() | |
| // 512 samples per frame, stereo input, mono output | |
| , processor = context.createJavaScriptNode(512, 2, 1) | |
| , sourceNode | |
| audio.addEventListener('canplaythrough', function(){ | |
| sourceNode = context.createMediaElementSource(audio) | |
| sourceNode.connect(processor) |