Skip to content

Instantly share code, notes, and snippets.

@pogin503
Created July 8, 2012 07:50
Show Gist options
  • Select an option

  • Save pogin503/3069861 to your computer and use it in GitHub Desktop.

Select an option

Save pogin503/3069861 to your computer and use it in GitHub Desktop.
console.log
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>$title</title>
$styles
</head>
<body>
<h1>$title</h1>
<p>
<input type="text" id="txt" value="Hello, $title!" />
<input type="button" id="btn" value="hello" />
</p>
$scripts
</body>
</html>
$ ->
$('#btn').on 'click', ->
alert $('#txt').val()
console.log 'Hello'
hello = -> console.log 'hello'
hello()
name = "test"
console.log "This is a #{name}"
test_func = (name) -> console.log "This is a #{name}"
test_func("foo")
square = (x) -> x * x
cube = (x) -> square(x) * x
console.log square(5)
console.log cube(5)
hit_and_blow = -> undefined
#generate_num :: (int) -> int
generate_num = (digit) ->
num = Math.random()
Math.floor (num*(Math.pow 10,digit))
console.log "gm "+generate_num(3)
exist_list = (digit) ->
str = generate_num(digit).toString()
#ary = ((str.charAt(i):false) for i in [0..digit-1])
console.log "exist "+exist_list(3)
#fizzbuzz
fizzbuzz = ->
for i in [1..100]
str = if i % 3 is 0 and i%5 is 0
"fizzbuzz"
else if i%3 is 0
"fizz"
else if i%5 is 0
"buzz"
else
i
console.log fizzbuzz().toString()
ary1 = [5,7,3,6,1]
bubble = (ary) ->
#undefined
###
temp = x[i]
x[i+1] = x[i]
x[i] = temp
###
#swap(ary,1)
for i in [0..ary.length-2]
if x[i] > x[i+1]
swap(ary,i)
###
intersection = (a, b) ->
[a, b] = [b, a] if a.length > b.length
value for value in a when value in b
###
bubble(ary1)
console.log ary1
#forとinの間に2つ変数を置きます。
arr = ["a", "b", "c", "d", "e"]
for val, i in arr
console.log "#{i}: #{val}"
# 数値当てゲーム
###
123
111 1b
112
113
121
122
123
131
132
133
211
212
213
221
222
223
231
232
233
311
312
313
321
322
323
331
332
333
123 3h
321 3B
ランダム関数
ビット判定(どの数字が出たか)
ヒットとブロウのカウント
###
body {
background: #eee;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment