Skip to content

Instantly share code, notes, and snippets.

@iksecreeet
iksecreeet / getLastInMap.js
Created May 7, 2020 11:46 — forked from tizmagik/getLastInMap.js
ES6 Last Item in Map()
// Since ES6 Map()'s' retain their order of insertion, it can sometimes be useful to get the last item or value inserted:
export const getLastItemInMap = map => Array.from(map)[map.size-1]
export const getLastKeyInMap = map => Array.from(map)[map.size-1][0]
export const getLastValueInMap = map => Array.from(map)[map.size-1][1]
// Obviously getLastKey and getLastValue can reuse getLastItem, but for maximum portability I opted for verbosity.
@iksecreeet
iksecreeet / GetWeeksInMonth.js
Created June 13, 2020 10:20 — forked from markthiessen/getWeeksInMonth.js
JavaScript - get weeks in a month as array of start and end days
//note: month is 0 based, just like Dates in js
function getWeeksInMonth(month, year){
var weeks=[],
firstDate=new Date(year, month, 1),
lastDate=new Date(year, month+1, 0),
numDays= lastDate.getDate();
var start=1;
var end=7-firstDate.getDay();
while(start<=numDays){
/**
* @param mixed $a
* @param mixed $b
*
* @return int
*/
protected function _sortSizes($a, $b)
{
$aUpper = strtoupper($a);
$bUpper = strtoupper($b);
@iksecreeet
iksecreeet / ObjectSize.php
Created December 9, 2020 13:43 — forked from mathiasschopmans/ObjectSize.php
Sort various (clothing) sizes in an array
<?php
class ObjectSize {
protected static $sizes = [
'xxxxl',
'xxxl',
'xxl',
'xl',
'l',