Skip to content

Instantly share code, notes, and snippets.

View hyuki's full-sized avatar

Hiroshi Yuki / 結城浩 hyuki

View GitHub Profile
def sqsum(x)
y = 0
x.to_s.split(//).each do |s|
a = s.to_i
y += a ** 2
end
y
end
def seq_sqsum(x)
@hyuki
hyuki / a.go
Created April 9, 2018 08:12
os.Args
package main
import (
"fmt"
"os"
)
func main() {
for index,cmd := range os.Args {
fmt.Printf("os.Args[%d] = %s\n", index,cmd)
@hyuki
hyuki / a.go
Created April 9, 2018 08:24
os.Open
package main
import (
"fmt"
"os"
"log"
)
func main() {
file, err := os.Open("sample.txt")
@hyuki
hyuki / a.go
Created April 9, 2018 08:30
bufio.NewScanner
package main
import (
"bufio"
"fmt"
"os"
"log"
)
func main() {
@hyuki
hyuki / a.go
Last active April 9, 2018 13:02
行番号付きでファイルを表示
package main
import (
"bufio"
"fmt"
"os"
"log"
)
func check(err error) {
@hyuki
hyuki / a.go
Last active April 9, 2018 13:00
os.Create, fmt.Fprintf
package main
import (
"bufio"
"fmt"
"os"
"log"
)
func check(err error) {
@hyuki
hyuki / a.go
Last active April 9, 2018 13:05
regexp.MatchString で「あ」で始まる行のみ表示する。
package main
import (
"bufio"
"fmt"
"os"
"log"
"regexp"
)
@hyuki
hyuki / a.go
Created April 9, 2018 12:24
与えられた文字列のSHA256ハッシュ値をもとにして6桁の数字列を作る
package main
import (
"crypto/sha256"
"fmt"
"strconv"
)
func main() {
sum := sha256.Sum256([]byte("hello world\n"))
@hyuki
hyuki / a.go
Created April 9, 2018 12:40
URL http://www.hyuki.com/ の内容をwgetで取得してoutput.htmlというファイルに落とす。
package main
import (
"os/exec"
"fmt"
"log"
)
func main() {
remote_name := "http://www.hyuki.com/"
@hyuki
hyuki / a.go
Created April 9, 2018 12:48
raw string literalsの練習
package main
import (
"fmt"
)
func main() {
prolog := `
<!DOCTYPE html>
<html>