Skip to content

Instantly share code, notes, and snippets.

View shinokada's full-sized avatar

Shinichi Okada shinokada

View GitHub Profile
# 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}
# 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|
# 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
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]
@shinokada
shinokada / index.html
Last active February 19, 2018 00:40
Learning React Chapter 3 Samples// source http://jsbin.com/kemimi/6
<!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>
@shinokada
shinokada / .gitignore_global
Created December 31, 2018 23:29
.gitignore_global
1 *# node_modules
2 node_modules/
3 # Compiled source #
4 ###################
5 *.com
6 *.class
7 *.dll
8 *.exe
9 *.o
10 *.so
@shinokada
shinokada / schema-org-structured-data-markup-using-microdata.html
Created June 24, 2019 06:58 — forked from milanaryal/schema-org-structured-data-markup-using-microdata.html
An example of how to mark up a HTML5 webpage using the schema.org schemas and microdata.
<!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">
from scipy.stats import chi2_contingency
import pandas as pd
import numpy as np
tshirts = pd.DataFrame(
[
[48,12,33,57],
[35,46,42,27]
],
index=["Male","Female"],
columns=["Balck","White","Red","Blue"])
tshirts
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.