Skip to content

Instantly share code, notes, and snippets.

@minedun6
minedun6 / enumerate-dates-by-period.js
Created January 23, 2020 09:17 — forked from gvko/enumerate-dates-by-period.js
Enumerate days, weeks, months or years
'use strict';
const moment = require('moment');
/**
* Returns a {key: value} object where the key is a start date and the value is the date + 1 of the type of interval
* to the start date. When for weeks or months, it shows just the first date of the week/month.
*
** For days (start: '2017-12-25', end: '2018-01-02', interval: 'day'):
{ '2017-12-25': '2017-12-26',
@minedun6
minedun6 / index.js
Created September 17, 2019 11:25
Compare 2 objects values @nicbell
//How To Compare Object Values
var a = { blah: 1 };
var b = { blah: 1 };
var c = a;
var d = { blah: 2 };
Object.compare = function (obj1, obj2) {
//Loop through properties in object 1
for (var p in obj1) {
//Check property exists on both objects
@minedun6
minedun6 / EventedDatastore.js
Created July 9, 2019 07:53 — forked from JamesMGreene/EventedDatastore.js
Forcibly adding NeDB events by deriving from the Datastore prototype
// IMPORTANT:
// As of nedb@^1.7.0, Datastore now inherits from EventEmitter in the NeDB core module.
// If you need to support older versions of NeDB, please look at the following previous revision
// of this gist:
// https://gist.github.com/JamesMGreene/0e0b2506c7bd2a2557f7/d8b4b1e97bb0d118c509672e3c7276b6dc4ba13a
/*
This gist provides a module which derives from the NeDB Datastore module and extends it to
emit several important events:
@minedun6
minedun6 / gist:f7f972f4cf43cd30076497c39d03c069
Last active June 17, 2019 15:48 — forked from dosjota/gist:9666a7274b4036588b92987b84267245
Downgrade php 7.2 to 7.1/7.0 in Ubuntu 18.04 LTS
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1
sudo apt-get install php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm php7.1-intl php7.1-simplexml
sudo a2dismod php7.2
sudo a2enmod php7.1
sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php7.1
sudo update-alternatives --set phar /usr/bin/phar7.1
sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.1
@minedun6
minedun6 / index.js
Last active June 13, 2019 08:32
Multiple api calls
// props to Mathias Bynens @mathias (twitter)
const promises = [
fetch('/api-call-1'),
fetch('/api-call-2'),
fetch('/api-call-3')
];
// imagine some of these requests fail and some succeed.
@minedun6
minedun6 / partition.js
Created May 13, 2019 21:59
Split an Array based on callback
Array.prototype.partition = function(predicate) {
const results = [[], []];
this.forEach((item, index) => {
results[predicate(item, index) ? 0 : 1].push(item);
});
@minedun6
minedun6 / index.js
Created May 2, 2019 07:54
I just shipped Promise.allSettled in Chrome 76
const promises = [
fetch('/api-call-1'),
fetch('/api-call-2')
];
// Imagine some of these requests fail, and some succeed.
const results = await Promise.allSetted(promises);
// [
@minedun6
minedun6 / tempory-upload.php
Created April 25, 2019 10:17
Tempory link to upload
<?php
$disk = Storage::disk('s3');
$disk->put($filename, fopen($this->filePath, 'r+'));
return Storage::disk('s3')->temporaryUrl($filename, now()->addWeek());
@minedun6
minedun6 / tinker_helper.php
Created February 7, 2019 10:20 — forked from calebporzio/tinker_helper.php
A quick, memorable way to initiate an "artisan tinker" session and play with variables.
<?php
function tinker(...$args) {
// Because there is no way of knowing what variable names
// the caller of this function used with the php run-time,
// we have to get clever. My solution is to peek at the
// stack trace, open up the file that called "tinker()"
// and parse out any variable names, so I can load
// them in the tinker shell and preserve their names.
<?php
's3-backups' => [
'driver' => 's3',
'key' => config('aws.public_key'),
'secret' => config('aws.secret_key'),
'region' => config('aws.region'),
'bucket' => $bucket_name
]