Skip to content

Instantly share code, notes, and snippets.

@swvitaliy
swvitaliy / tornadoko.py
Created June 15, 2012 10:54
makes tornado handlers like Kohana controllers
# -*- coding: utf-8 -*-
__author__ = 'vit'
import tornado.web
class Handler(tornado.web.RequestHandler):
def _calling(self, http_method, action_name, args):
if http_method != 'get' and http_method != 'post':
raise tornado.web.HTTPError(405)
#
# Имеется груз массой massa и набор весов, указанных в таблице
#
# create table m ( n int unsigned not null auto_increment, w int not null, primary key(n) );
# insert into m values (NULL, 3), (NULL, 5), (NULL, 4);
#
# где n - порядковый номер веса (без разрывов), w - вес
#
# Можно ли указанными в таблице весами взвесить груз массой massa?
#
#
# В декартовой СК на плоскости имеется набор окружностей одинакового радиуаса r.
#
# Таблица с центрами окружностей:
#
# create table p ( x int, y int );
#
# Нужно найти максимальное количество окружностей, которые польностью покроет
# окружность указанного радиуса Rg
#
@swvitaliy
swvitaliy / a.php
Created August 18, 2012 12:03
Php extension removes the specified directory for files
$s='/home/vit/plint/modules/';$a = dir('/home/vit/plint/modules'); while (FALSE !== ($b = $a->read())) { if( ($b === '.' || $b === '..') || is_dir($s.$b)) continue; if (preg_match('/\.php$/',$b)) { $c=substr($b, 0, strlen($b) - 4); print($b . "\t--->\t" . $c . "\t\t\t\t" . (rename($s . $b, $s . $c) ? "OK" : "FAILED!") . "\n"); } }
@swvitaliy
swvitaliy / upload.html
Created October 6, 2012 06:04
Simple imajao upload photo
<html>
<head>
<title>ava</title>
</head>
<body>
<form action="http://api.imajao.com/1.0.1/user/edit" method="POST" enctype="multipart/form-data">
<input name="apikey" value="cfcd208495d565ef66e7dff9f98764da" />
<input name="token" value="spy1p1gxjk0vtanx5vtwyg21sewru8eo" /><br>
<input type="file" name="avatar"> <input type="submit"></form>
</body>
@swvitaliy
swvitaliy / ps1
Created October 6, 2012 09:52
ps1
PS1="\w [\e[0;34m`git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/'`\e[0m]\n$ "
PS1="\e[2;36m\t\e[0m \w \e[1;33m`git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/'`\e[0m\n$ "
PS1="\w \e[1;33m`git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/'`\e[0m\n$ "
@swvitaliy
swvitaliy / 2 mongo connections
Created October 14, 2012 07:48
mongodb 2 parallel db connection
var connect = require('connect'),
http = require('http'),
mongodb = require('mongodb'),
db1, db2;
db1 = new mongodb.Db('first', new mongodb.Server('127.0.0.1', 27017, {}));
db2 = new mongodb.Db('second', new mongodb.Server('127.0.0.1', 27017, {}));
@swvitaliy
swvitaliy / gist:3903784
Created October 17, 2012 05:00
js maxTimeout
var maxTimeoutLoopExecutionTemplate = "(function (maxTimeout, fn, delay) {" +
" var t;" +
" setTimeout(function () { clearTimeout(t); }, maxTimeout);" +
" t = (function z() { return setTimeout(function () { fn(); t = z(); }, delay); })();" +
"})(:maxtimeout, function () { :expression }, :delay);";
@swvitaliy
swvitaliy / mc.js
Created November 12, 2012 21:14
model-collection
(function() {
function extend(obj) {
Array.slice.call(arguments, 1).forEach(function(source) {
for (var prop in source) {
obj[prop] = source[prop];
}
});
return obj;
};
(function() {
function extend(obj) {
Array.prototype.slice.call(arguments, 1).forEach(function(source) {
for (var prop in source) {
obj[prop] = source[prop];
}
});
return obj;
};