Skip to content

Instantly share code, notes, and snippets.

View Dartv's full-sized avatar
🌚
...

Dmytro Artamonov Dartv

🌚
...
View GitHub Profile
@Dartv
Dartv / gist:34b40c8cd38c1cbaf50ea336a99a72a1
Created May 17, 2023 07:52
list node packages and their supported node versions
npm ls -depth=0 -prod | sed -n 's/^[^A-Za-z0-9_]*//;s/@.*$//p' | xargs -n 1 -I % sh -c 'echo %; npm view % engines'

Keybase proof

I hereby claim:

  • I am dartv on github.
  • I am dartv (https://keybase.io/dartv) on keybase.
  • I have a public key ASA1g4OhElCo1UZGqsDcQvgQ1jAUB2rDiLPi9hFX8Wlrswo

To claim this, I am signing this object:

@Dartv
Dartv / itunes_lower_volume.js
Created September 12, 2017 03:18
Itunes userscript to lower volume
// ==UserScript==
// @name Itunes lower volume
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://itunes.apple.com/*/album/*/*$
// @grant none
// ==/UserScript==
const getOffset = (offset, index, arr) => arr[(arr.length + index + (offset % arr.length)) % arr.length]
const $chat = $('.chat-content');
const $message = $(ReactDOM.findDOMNode(component));
const msgOffset = $message.offset().top;
// center the linked message in the chat box
const elHeight = $message.height();
const chatHeight = $chat.height();
const offset = msgOffset - ((chatHeight / 2) - (elHeight / 2));
@Dartv
Dartv / max.js
Created October 9, 2015 06:02
Unique objects from array with max property
arr = [
{ id: 324, difficulty: 3 },
{ id: 324, difficulty: 2 },
{ id: 324, difficulty: 5 },
{ id: 500, difficulty: 3 },
{ id: 500, difficulty: 3.5 },
{ id: 500, difficulty: 7 }
];
let map = _.groupBy(arr, (el) => el.id)
@Dartv
Dartv / remove_dups.js
Created October 1, 2015 20:28
Remove duplicates and leave one document with the most difficultyrating
db.beatmaps.aggregate([
{
"$group": {
"_id": "$beatmapset_id",
"count": { "$sum": 1 },
"uniqueIds": { "$addToSet": "$_id" },
"maxRating": { "$max": "$difficultyrating" }
}
},
@Dartv
Dartv / keys.es6
Created September 22, 2015 15:21
Loop through array of keys and make an object with given values or null
handleQueries(queries, values) {
let obj = {};
for (let i = 0; i < queries.length; i++) {
obj[queries[i]] = this[queries[i]]() ? values[i] : null;
}
let vals = _.values(obj).filter(x => x !== null);
return vals;
}
@Dartv
Dartv / freq.js
Created September 21, 2015 14:46
Calculating frequency
let nums = [30, 36, 37, 41, 42, 41, 40, 41, 46, 47, 46, 46, 47, 45, 46, 45, 50, 51, 50, 52, 52, 51, 51, 52, 50, 50, 56, 55, 56, 57, 57, 57, 57, 58, 58, 55, 61, 62, 67, 67];
let unique = _.unique(nums);
let absoluteFrequency = _.countBy(nums, num => num);
let relativeFrequency = () => {
let obj = {};
let values = _.values(absoluteFrequency);
let keys = _.keys(absoluteFrequency);
for (var i = 0; i < keys.length; i++) {
obj[keys[i]] = values[i] / nums.length;
}