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://slobin.livejournal.com/515819.html | |
import math | |
def interval(k, n): | |
# http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval | |
# Wilson score interval | |
z = 1.96 #95% confidence | |
p = 1.0*k / n |
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
import random | |
def main(): | |
basket = [0]*5 | |
rand = random.randrange | |
for i in xrange(27777777): | |
basket[rand(0, 5)%5] += 1 | |
for v in basket: |
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
// Determine support properties | |
(function( xhr ) { | |
jQuery.extend( jQuery.support, { | |
ajax: !!xhr, | |
cors: !!xhr && ( "withCredentials" in xhr ) | |
}); | |
})( jQuery.ajaxSettings.xhr() ); |
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
#include "may_be.hpp" | |
#include <iostream> | |
struct Point { //тип, над которым мы будем эксперементировать. | |
float x, y; | |
Point(float x, float y): x(x), y(y) {} | |
Point(): x(0), y(0) {} | |
}; |
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
#include "may_be.hpp" | |
#include <iostream> | |
struct Point { //тип, над которым мы будем эксперементировать. | |
float x, y; | |
Point(float x, float y): x(x), y(y) {} | |
Point(): x(0), y(0) {} | |
}; |
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
#ifndef MAY_BE_HEADER | |
#define MAY_BE_HEADER | |
#include <string.h> | |
#include <memory> | |
#include <assert.h> | |
///для того, что бы удобней было вернуть из функции пустое или дефолтное значение, например | |
/** \code | |
MayBe<Point> f() { |
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
#ifndef MAY_BE_HEADER | |
#define MAY_BE_HEADER | |
#include <string.h> | |
#include <memory> | |
#include <assert.h> | |
///для того, что бы удобней было вернуть из функции пустое или дефолтное значение, например | |
/** \code | |
MayBe<Point> f() { |
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
#include <boost/shared_ptr.hpp> | |
#include <iostream> | |
struct T { | |
boost::shared_ptr<MayBe<T> > next; | |
int i; | |
T() { i = 10; } | |
}; |
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
import re | |
def f1(c): | |
return c in ''' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\\'()*-.:<>[]^`{|}~''' | |
ALLOWED = re.compile('''[ a-zA-Z0-9!"'()*.:<>^`{|}~\\\[\]-]''') | |
def f2(c): | |
return bool(re.match(ALLOWED, c)) | |
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
# Ivan Dobrokotov, dobrokot 'at' gmail.com | |
def calc_moves(x, y): | |
result = [] | |
for dx, dy in [(1, 2), (2, 1), (-1, 2), (-2, 1), (-1, -2), (-2, -1), (1, -2), (2, -1)]: | |
nx, ny = (x + dx, y+dy) | |
if 0 <= nx < 8 and 0 <= ny < 8: | |
result.append((nx, ny)) | |
return result | |