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
list = [37, 38, 39, 40, 41] | |
list.shuffle.each_slice(4) do |team| | |
p team.sort | |
end |
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
func add(x: Int)(y: Int) -> Int { | |
return x + y | |
} | |
let add100 = add(100) // 這邊等於產生了一個會加 100 的 function | |
println(add100(y:20)) // 得到 120 |
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
# rb_ary_join | |
VALUE | |
rb_ary_join(VALUE ary, VALUE sep) | |
{ | |
long len = 1, i; | |
int taint = FALSE; | |
int untrust = FALSE; | |
VALUE val, tmp, result; |
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
Question 1 | |
>> 2.21 * 7 | |
=> 15.469999999999999 | |
>> "%0.2f" % (2.21 * 7) | |
=> "15.47" | |
Question 2 | |
>> 3.1415.round(3) | |
=> 3.142 |
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
extension Int { | |
func times(task:() -> ()) { | |
for i in 0..self { | |
task() | |
} | |
} | |
} | |
5.times { | |
println("Hey! You look really like Ruby") |
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
aaa |
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
require "faker" | |
names = [] | |
20.times do | |
names << Faker::Name.last_name | |
end | |
p names |
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
f = open('access.log') | |
ip_list = {} | |
for line in f.readlines(): | |
ip = line.split(' ')[0] | |
ip_list[ip] = ip_list.get(ip, 0) + 1 | |
f.close() | |
sorted_ip_list = sorted(ip_list.items(), key=lambda x: x[1]) |
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
// | |
// ViewController.m | |
// buttonDemo | |
// | |
// Created by 高 見龍 on 13/9/22. | |
// Copyright (c) 2013年 高 見龍. All rights reserved. | |
// | |
#import "ViewController.h" |
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
// NSObject+Utils.h | |
#import <Foundation/Foundation.h> | |
@interface NSObject (Utils) | |
- (BOOL) isNull; | |
- (BOOL) isNotNull; | |
@end |