Skip to content

Instantly share code, notes, and snippets.

BaseBallGame.prototype.pitch = function(toHitting, toBunt, score) {
var strike_prob = 0.6;
var goro_prob = 0.3;
var swing_miss_prob = 0.2;
var hit_prob = [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4];
var strike = Math.random() > strike_prob;
var base = hit_prob[parseInt(Math.random() * 10, 10)];
var isHit = false;
var isGoro = Math.random() < goro_prob;
var isSwingMiss = false;
@cou929
cou929 / ex.py
Created June 23, 2011 18:01
expand pattern and return sequence
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
ex.py
expand pattern and return sequence.
Kosei Moriyama <[email protected]>
@cou929
cou929 / wiki2rst.py
Created June 26, 2011 09:10
convert bitbucket style wiki notation to ReStructured Text (ReST)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
wiki2rst.py
convert bitbucket style wiki notation to ReStructured Text (ReST)
Kosei Moriyama <[email protected]>
@cou929
cou929 / centos_mail_bootstrap.sh
Created September 3, 2011 16:50
Postfix and dovecot setup script for CentOS (instead of sendmail)
#! /bin/sh
# postfix and dovecot setup script (instead of sendmail)
# based on http://centossrv.com/postfix.shtml
echo "### install postfix via yum if not exist"
if [ ! -e /etc/postfix/main.cf ]
then
sudo yum -y install postfix
else
@cou929
cou929 / tcget.py
Created December 3, 2011 10:49
old
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
tcget.py
Kosei Moriyama <[email protected]>
'''
import BeautifulSoup
@cou929
cou929 / changelog2posterous.rb
Created January 9, 2012 03:10
Send changelog entry to posterous
#! /usr/bin/ruby
posterous_mailto = '[email protected]'
## get stdin
is_head = true
header = ''
body = ''
while line = gets
@cou929
cou929 / sendgmail.py
Created January 9, 2012 10:49
Send mail via GMail smtp.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
import sys
import os
from email.MIMEText import MIMEText
from email.Utils import formatdate
from email.Header import Header
from optparse import OptionParser
@cou929
cou929 / nonblock_apue12.c
Created January 29, 2012 02:22
test of O_NONBLOCK from APUE Chapter 12
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
void set_fl(int fd, int flags);
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="https://raw.github.com/visionmedia/mocha/master/mocha.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://raw.github.com/LearnBoost/expect.js/d2440da086bf8dc38c6085641f23b968a0f48b29/expect.js"></script>
<script src="https://raw.github.com/visionmedia/mocha/master/mocha.js"></script>
<script src="ajax.js"></script>
<script>mocha.setup('bdd')</script>
(function() {
describe('Mocha itself on client-side', function() {
it('should works well!', function() {
expect(5).to.be.a('number');
});
});
if (!Object.create) {
Object.create = function (o) {
if (arguments.length > 1) {