const timeline = {start: 100, end: 300 }
const offsets = []
const items = [
{ start: 235, end: 270 },
{ start: 135, end: 170 },
]
.sort((a,b) => {
if(a.end > b.end) {
return 1
}
if(a.end < b.end) {
return -1
}
return 0
})
items.forEach((cur, index, arr) => {
// Start
if(index === 0) {
offsets.push({
start: timeline.start,
end: timeline.start + cur.start - timeline.start
})
}
// Middle
if(arr[index+1]) {
offsets.push({
start: cur.end,
end: cur.end + arr[index+1].start - cur.end
})
}
// End
if(index === arr.length - 1) {
offsets.push({
start: cur.end,
end: timeline.end
})
}
})
console.log(offsets)
/*
Result:
[ { start: 100, end: 135 },
{ start: 170, end: 235 },
{ start: 270, end: 300 } ]
*/
const https = require('https')
const url = "https://tproger.ru/wp-content/plugins/citation-widget/get-quote.php?_=1548878205977"
let query = () =>{
return new Promise((resolve,reject)=>{
https.get(url,resp=>resp.on('data',chunk=>resolve(chunk.toString())))
})
};
let queryList = [...Array(5).keys()].map(el=>query())
let main = async()=>{
let results = await Promise.all(queryList).then(data=>data)
console.log(results)
}
main();
$(document).ready(function() {
var newcount = $(".total_number").data("products_total_number");
var allprice = $(".fullprice").data("her");
$("#price").html(allprice);
var btnn = $("#submit_btn");
var form = $(".formselect");
form.on('submit', function(e) {
e.preventDefault();
var product_id = $(".info").data("product_id");
var product_name = $(".info").data("product_name");
var price = $(".info").data("product_price");
var quantity = $("#sel1").val();
var full_price_per_item = (price * quantity);
newprice = allprice + (price * quantity);
allprice = newprice;
newcount++;
$(".count").html(newcount);
var data = {};
data.product_id = product_id;
data.product_name = product_name;
data.product_price = price;
data.product_quantity = quantity;
data.product_newprice = newprice;
data.product_newcount = newcount;
data.product_allprice = allprice;
var csrf_token = $('.formselect [name="csrfmiddlewaretoken"]').val();
data["csrfmiddlewaretoken"] = csrf_token;
var url = form.attr("action");
console.log(data);
$.ajax({
url: url,
type: 'POST',
data: data,
cache: true,
success: function(data) {
console.log("OK");
console.log(data.products)
$.each(data.products, function() {
$(".basket-item ul").append('<li class="del">' + '<span class="goods">Goods:' + product_name + '</span>' +
'<span class="quantity"> Quantity:' + '<span class="count_of_quantity">' + quantity + '</span>' + '</span>' +
'<a href="#" class="deleteitem">X</a>' + '<span class="hidden del_price">' + full_price_per_item + '</span>' + "</li>")
})
},
error: function(data) {
console.log("ERROR");
}
});
$(".liii").mouseover(function(e) {
e.preventDefault();
$(this).addClass("cartcolor");
});
$(".liii").mouseout(function(e) {
e.preventDefault();
$(this).removeClass("cartcolor");
});
$(".basket-container").mouseover(function(e) {
e.preventDefault();
$(".basket-item").removeClass("hidden");
$("#submit_btn").removeClass("hidden");
});
$(".basket-container").mouseout(function(e) {
e.preventDefault();
$(".basket-item").addClass("hidden");
$("#submit_btn").addClass("hidden");
});
$(document).on('click', '.deleteitem', function(e) {
e.preventDefault();
var cost = $(this).closest('li').find(".del_price").html();
$(this).closest('li').remove();
var allprice = $(".fullprice").data("her");
console.log(allprice);
newprice = allprice - cost;
allprice = newprice;
newcount--;
$(".count").html(newcount);
$("#price").html(newprice);
});
});
});
import os,re,sys
folder = sys.argv[1]
path = os.listdir(folder)
log = open(os.path.join(folder,'log.txt'),'w')
for j in path:
if "txt" in j:
words =0
f=os.path.join(folder,j)
with open(f) as file:
for line in file:
words+=len(re.findall('\w+', line))
log.write(j+' = '+str(words)+' words'+'\n')
log.close()