Skip to content

Instantly share code, notes, and snippets.

@iksecreeet
iksecreeet / get_average_age
Last active November 19, 2019 07:08
Пример JSON ( продолжительность жизни на основе даты и пола). При исходных данных(пол: жен, дата рождения 22 апреля 1977)
{
"data": {
"currentAge": 36.80011267063039,
"yearsLeft": 43.607894089607434,
"monthsLeft": 523.2947290752892,
"daysLeft": 15927.783316229115,
"hoursLeft": 382266.7995894988,
"minutesLeft": 22936007.975369927,
"secondsLeft": 1376160478.5221956,
"dateString": "43 years 7 months 8 days 23 hours 17 minutes 42 seconds",
@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 / error-metro-config
Created May 16, 2020 13:23
Error metro-config npm start
Got this issue today on windows, but don't need to downgrade node, just as discussed on stackoverflow just need to change some hashes on your project:
\node_modules\metro-config\src\defaults\blacklist.js
var sharedBlacklist = [
/node_modules[/\\]react[/\\]dist[/\\].*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/
];
@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){
@iksecreeet
iksecreeet / iap_receipt.js
Created August 24, 2020 07:55
Get receipt RN IAP
import * as RNIap from 'react-native-iap';
RNIap. getPurchaseHistory().then((purchaseHistory) => {
if(purchaseHistory.length > 0) {
const getLastPurchase = purchaseHistory[purchaseHistory.length -1];
const getReceipt = getLastPurchase.transactionReceipt;
// DO RECEIPT RELATED TASK
}
});
/**
* @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',