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
# http://batsov.com/articles/2013/12/04/using-rubys-each-with-object/ | |
nums = [1, 1, 2, 3, 3, 5] | |
nums.each_with_object(Hash.new(0)) { |e, a| a[e] += 1 } | |
# => {1=>2, 2=>1, 3=>2, 5=>1} | |
nums = [1, 1, 2, 3, 3, 5] | |
nums.reduce(Hash.new(0)) { |a, e| a[e] += 1; a } | |
# => {1=>2, 2=>1, 3=>2, 5=>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
# http://blog.flatironschool.com/post/35154441787/rubys-each-with-object | |
hash = {} | |
['red', 'green', 'blue'].each do |color| | |
hash[color] = 'primary' | |
end | |
# Using inject, we don't have to initialize the hash ahead of time | |
['red', 'green', 'blue'].inject({}) do |hash, color| |
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
# I struggled how to add input data to an array in a hash value and these art some | |
# ways to do. [See more examples](http://judge.u-aizu.ac.jp/onlinejudge/solution.jsp?pid=0105#6). | |
#Using an array hash[word] = [page.to_i] | |
# and using has_key? | |
hash = {} | |
while n = gets | |
word, page = n.split | |
hash.has_key?(word) ? hash[word] << page.to_i : hash[word] = [page.to_i] | |
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
r = 10..1 | |
p (r.first).downto(r.last).to_a | |
# [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
p (1..10).reverse_each.to_a | |
# [10, 9, 8, 7, 6, 5, 4, 3, 2, 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[add your bin description]"> | |
<script src="https://fb.me/react-with-addons-15.1.0.js"></script> | |
<script src="https://fb.me/react-dom-15.1.0.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=1.0, user-scalable=no" /> | |
<title>Learning React Chapter 3 Samples</title> | |
</head> |
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
1 *# node_modules | |
2 node_modules/ | |
3 # Compiled source # | |
4 ################### | |
5 *.com | |
6 *.class | |
7 *.dll | |
8 *.exe | |
9 *.o | |
10 *.so |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> | |
<title>Site Title</title> | |
<link rel="stylesheet" href="/assets/css/style.min.css"> |
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
from scipy.stats import chi2_contingency | |
import pandas as pd | |
import numpy as np |
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
tshirts = pd.DataFrame( | |
[ | |
[48,12,33,57], | |
[35,46,42,27] | |
], | |
index=["Male","Female"], | |
columns=["Balck","White","Red","Blue"]) | |
tshirts |
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
chi, pval, dof, exp = chi2_contingency(subjects) | |
significance = 0.05 | |
p = 1 - significance | |
critical_value = chi2.ppf(p, dof) | |
print('chi=%.6f, critical value=%.6f\n' % (chi, critical_value)) | |
if chi > critical_value: | |
print("""At %.2f level of significance, we reject the null hypotheses and accept H1. |