Skip to content

Instantly share code, notes, and snippets.

View PostScripton's full-sized avatar

Sergey Podzemelnykh PostScripton

View GitHub Profile
@PostScripton
PostScripton / laravel_update_records_in_production_from_google_sheets.md
Last active January 21, 2023 18:02
Laravel: Update records in the DB from a Google Sheets file

Introducing

If you've been told to update a list of records with the new values in the DB, and it's hard to do it manually, you can run a script within Tinker.

A Google Sheet table structure

The structure might look something like this:

image

@PostScripton
PostScripton / Sorting an array by frequency of occurence.js
Last active October 12, 2020 08:35
Allows to sort an array by frequency of occurence in JS
const arr = [1, 2, 4, 5, 5, 5, 2, 4, 3, 4, 3, 3, 2, 3, 2, 1, 1, 2, 1]
Array.prototype.sortByFrequency = function () {
let frequency = {}
let sorting = []
let new_arr = []
this.forEach(value => frequency[value] = (frequency[value] || 0) + 1)
for (let key in frequency)sorting = [...sorting, [key, frequency[key]]]