Skip to content

Instantly share code, notes, and snippets.

dobrokot

Block or report user

Report or block dobrokot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:1272281
// Determine support properties
(function( xhr ) {
jQuery.extend( jQuery.support, {
ajax: !!xhr,
cors: !!xhr && ( "withCredentials" in xhr )
});
})( jQuery.ajaxSettings.xhr() );
@dobrokot
dobrokot / may_be.hpp
Created Apr 10, 2012
nullable/optinal/MayBe - store some value or empty.
View may_be.hpp
#ifndef MAY_BE_HEADER
#define MAY_BE_HEADER
#include <string.h>
#include <memory>
#include <assert.h>
///для того, что бы удобней было вернуть из функции пустое или дефолтное значение, например
/** \code
MayBe<Point> f() {
@dobrokot
dobrokot / may_be.hpp
Created Apr 10, 2012
nullable/optinal/MayBe - store some value or empty
View may_be.hpp
#ifndef MAY_BE_HEADER
#define MAY_BE_HEADER
#include <string.h>
#include <memory>
#include <assert.h>
///для того, что бы удобней было вернуть из функции пустое или дефолтное значение, например
/** \code
MayBe<Point> f() {
@dobrokot
dobrokot / may_be_usage.cpp
Created Apr 10, 2012
Shows usage of may_be.hpp
View may_be_usage.cpp
#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) {}
};
@dobrokot
dobrokot / may_be_usage.cpp
Created Apr 10, 2012
Shows usage of may_be.hpp
View may_be_usage.cpp
#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) {}
};
View gist:2355107
#include <boost/shared_ptr.hpp>
#include <iostream>
struct T {
boost::shared_ptr<MayBe<T> > next;
int i;
T() { i = 10; }
};
@dobrokot
dobrokot / gist:2470067
Created Apr 23, 2012
compare set contains element on strings of ~tens symbols
View gist:2470067
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))
View knight_random_walk.py
# 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
@dobrokot
dobrokot / tree_cost.py
Created May 11, 2012
minimal tree cost built from list
View tree_cost.py
# minimal tree cost built from list, problem from http://antilamer.livejournal.com/431230.html
# cost of tree is sum(depth(i)*value(i))
list = [1,2,3,4,5,7,6,5,4,3,2,10000]
n = len(list)
#table from (start, length) to (cost, x-sum, root) for best tree on segment (start, length)
table_start_l = [[(0,0,-1000)]*(n-start+1) for start in xrange(n+1)]
@dobrokot
dobrokot / segment_intersection.cpp
Created May 20, 2012
segments robust intersection code
View segment_intersection.cpp
#include <stdio.h>
struct Point2f {
float x, y;
Point2f(float _x, float _y): x(_x), y(_y) {}
Point2f(): x(0), y(0) {}
};
Point2f operator -(Point2f p1, Point2f p2) {
You can’t perform that action at this time.