Skip to content

Instantly share code, notes, and snippets.

View Vishal-Isharani's full-sized avatar
🏠
Working from home

Vishal Isharani Vishal-Isharani

🏠
Working from home
View GitHub Profile
@umidjons
umidjons / sort-object-properties-by-value.md
Last active October 9, 2024 10:31
JavaScript: sort object properties by value (numeric or string)

Sort object properties by value (values are text)

I have following object:

var cities={10:'Tashkent', 14:'Karakalpakiya', 16:'Andijan'};

I want sort it by city names, so after sort it should be:

var cities={16:'Andijan', 14:'Karakalpakiya', 10:'Tashkent'};

But I can't sort object properties, instead can convert object into array, then sort items.

@miguelmota
miguelmota / getDates.js
Last active May 22, 2025 04:15
Get dates in between two dates with JavaScript.
// Returns an array of dates between the two dates
function getDates (startDate, endDate) {
const dates = []
let currentDate = startDate
const addDays = function (days) {
const date = new Date(this.valueOf())
date.setDate(date.getDate() + days)
return date
}
while (currentDate <= endDate) {
@apb2006
apb2006 / app-basex.js
Last active June 25, 2016 13:59
Node.js + socket.io + BaseX = Xquery chatbot
// Andy bunce jan 2013 based on http://book.mixu.net/ch13.html
var fs = require('fs'),
http = require('http'),
sio = require('socket.io');
var port=8001;
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-type': 'text/html'});
res.end(fs.readFileSync('./index.html'));
});
server.listen(port, function() {