Skip to content

Instantly share code, notes, and snippets.

function eventEmitter() {
const state = {}
return {
subscribe: (channel, fn) => {
state[channel] = fn
},
emit: (channel, ...param) => {
if (state[channel]) {
state[channel](...param)
}
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)
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')
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
@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)
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
var dictinary = {};
function addWord(word, value) {
value = value ? value : word
var letters = word.split('')
var newDic = letters.reduce((prev, curr, i) => {
if (letters.length -1 === i) {
return prev[curr] = value
}
return prev[curr] ? prev[curr] : prev[curr] = {}
<audio src="song.mp3" id="myAudio"></audio>
/*
нужно расчитать график касиров
каждый касир должен работать не больше 5 дней в неделю И не больше 9 часов в день
рабочий день начинаеться с 8 до 23 - 15 раб часов
* ---------------------
const kAll = 70 // кол-во касиров всего
let k = 0 // кол-во касиров в день (нужно найти эту переменную)
let p = 0 // поток покупателей
let t = 0 // время (от 8 до 23)
<!DOCTYPE html>
<html>
<head>
<title>brain</title>
</head>
<body>
<script type="text/javascript">
/*------example------
exampleInputData = [0,1,2,3,4,5,6]
exampleOutputData = [1,3,5]