Skip to content

Instantly share code, notes, and snippets.

def file(name, flag = False):
f = open(name)
if flag == 'w':
return f
return f.readlines()
def readfile(filename):
lines = [line for line in file(filename)]
print(len(lines))
# First line is the column titles
@SergProduction
SergProduction / cancelablePromise.js
Last active August 25, 2017 10:03
cancelable promis and react hoc
export const cancelablePromise = (promise) => {
let state = false
const prom = (...param) =>
new Promise((resolve, reject) => {
promise(...param)
.then((res) => {
if (!state) resolve(res)
})
.catch((err) => {
if (!state) reject(err)
class Perceptron {
constructor(bias=1,learningRate=0.1,weights=[]) {
this.bias = bias;
this.learningRate = learningRate;
this.weights = weights;
this.trainingSet = [];
}
init(inputs,bias=this.bias) {
// Initialize weights to 0 and adding bias weight
const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const WebpackBabelExternalsPlugin = require('webpack-babel-external-helpers-2')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
import React from 'react'
import { render } from 'react-dom'
import { routes } from './scheme-route'
import { StaticRouter } from 'react-router-dom'
render((
<StaticRouter>
{routes}
</StaticRouter>
), 0)
function eventEmitter() {
const state = {}
return {
subscribe: (channel, fn) => {
state[channel] = fn
},
emit: (channel, ...param) => {
if (state[channel]) {
state[channel](...param)
}
compose = (...fns) =>
fns.reduceRight((prevFn, nextFn) =>
(...args) => nextFn(prevFn(...args)),
value => value
)
composeWithState = (...fns) => (res) => fns.reduceRight((value, fn) => fn(value, res), res)
const closest = (arr, g) =>
arr.reduce((prev, cur) =>
/**
* @param {object[]} data [{ name:'group', [elementName]:[] }, ...]
* @param {number} columns 3
* @param {number} groupHeight высота между групапами, 1 эквивалентно высоте одного элемента группы
* @param {string} elementName имя свойства элементов в группе
* @returns {object[]} [{ column:1, data: [group, ...] }, ...]
*/
function sortGroupColumn(data, columns, groupHeight, elementName) {
// в каком столбце какие данные (data); len - общее кол-во значений в группах
const column = {}
function equalInterface(sample, eq) {
const type = t => Object.prototype.toString.call(t).slice(8,-1).toLocaleLowerCase()
debugger
let isEqual = true
if (type(sample) === 'object') {
Object.keys(sample).forEach(key => {
if (type(sample[key]) === 'object') {
const intoIsEqual = equalInterface(sample[key], eq[key])
console.log(sample[key], eq[key], intoIsEqual)
/* eslint-disable func-names, no-underscore-dangle */
import EventBus from 'vertx3-eventbus-client'
const delayObserver = (timeCount) => {
const state = []
let stop = false
return ({
emmit: () => {
if (stop) return false