Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View MarkLavrynenko's full-sized avatar

Mark Lavrynenko MarkLavrynenko

View GitHub Profile
@MarkLavrynenko
MarkLavrynenko / gist:5b763e36b128170cdb77
Created June 5, 2015 17:02
Download Pdf file using AJAX (angular)
angular.module("test-app", [])
.controller("PDFDownloadController", ["$scope", "$http", function($scope, $http) {
function handleResponse(response){
var pdfFile = new Blob([response.data], { type : 'application/pdf' })
var downloadURL = URL.createObjectURL(pdfFile);
var link = document.createElement('a');
link.href = downloadURL;
link.download = "preview.pdf"
document.body.appendChild(link);
link.click();
import string
class Node:
def __init__(self):
self._links = {}
self._is_finite = False
def set_link(self, letter, node):
if letter == '.':
@MarkLavrynenko
MarkLavrynenko / gist:e411985a9dd0a496f7b3
Last active August 29, 2015 14:23
Discardable distributed job
from multiprocessing import Process, Manager, Event
from random import randint
children_count = 5
block_size = 10000
def find(my_id, found):
print("Process with id %s has been started" % my_id)
left = block_size * my_id
right = left + block_size
@MarkLavrynenko
MarkLavrynenko / gist:02711dc9c16242afd96f
Created June 27, 2015 17:42
Interesting thing with Pipe
from multiprocessing import Pool, Pipe, Process
def work(process_name, pipe):
while True:
print("%s Start w8!" % process_name)
data = pipe.recv()
print("%s You sent %s" % (process_name, data))
if __name__ == "__main__":
@MarkLavrynenko
MarkLavrynenko / gist:74783a5329ce957e2bf0
Created June 27, 2015 09:35
Python process safe queue usage example and logging from multiple processes
from multiprocessing import Process, Queue
from time import sleep
def func(q, cnt, log):
for i in range(0, cnt):
item = q.get()
message = "Got an item %s\n" % item
log.put(message)
if __name__ == '__main__':
@MarkLavrynenko
MarkLavrynenko / gist:93c12dbd0ef5636e154b
Created May 16, 2015 10:20
Artificial Intelligence
/*
# 1) a, b- min(x) a^x <= b
# 2) list - a, b; (a - b ) union (b - a)
# 3) a - find last atom
# 4) depth - the deepest sublist with sublists
# 5) sublists count
# 6) лінеаризація
# 7) min-max tree optonal
*/
angular.module('geomApp')
.controller('MainCtrl', function ($scope) {
$scope.testesTriangles = [];
//$scope.points = [{x: 40, y: 400},
// {x: 16, y: 300},
// {x: 230, y: 200},
// {x: 430, y: 100},
// {x: 330, y: 400},
// {x: 130, y: 270}];
$scope.points = [{x: 116, y: 300}];
#from os import urandom
from random import randint
from time import *
__author__ = 'mlavrynenko'
smal_rsa_primes = [
2 , 3 , 5 , 7 , 11 , 13 , 17 , 19,
23 , 29 , 31 , 37 , 41 , 43 , 47 , 53,
59 , 61 , 67 , 71 , 73 , 79 , 83 , 89,
]
<html>
<head>
<title>English learner</title>
<link rel="stylesheet" type="text/css" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="1.css">
</head>
<body ng-app="LearnerApp" ng-controller="WordCtr">
<div class="navbar navbar-static">
<div class="container">
<div class="navbar-header">
@MarkLavrynenko
MarkLavrynenko / gist:9bec7928d30a47507988
Last active August 29, 2015 14:17
Tree Traversal Lisp
;(load "1.lsp")
(setq tree '(1 (2 5) 6 (10 (14 (25 27) 40))))
(print tree)
(defun traverse-tree(tree depth)
(if (atom tree)
(progn (funcall func tree) (return-from traverse-tree))
)
(let ((list-len (length tree)))