Skip to content

Instantly share code, notes, and snippets.

View eleazarbr's full-sized avatar

Eleazar Resendez eleazarbr

View GitHub Profile
@eleazarbr
eleazarbr / formdata.js
Created January 8, 2021 23:00
How to create a FormData from an object and send an image to the backend using axios
// In this example you can see how to create a FormData from an object.
// This, in conjunction with axios, can be used to send an image to the back-end.
var formData = new FormData()
formData.append('_method', 'PUT')
for (const [key, value] of Object.entries(myObject)) {
formData.append(key, JSON.stringify(value))
}
if (this.image != null) formData.append('image', this.image)
@eleazarbr
eleazarbr / allowed-memory-size.md
Created December 20, 2020 20:27
How to solve: PHP Fatal error: Allowed memory size. (Composer)

We can run:

php -d memory_limit=-1 $(which composer) update

Or change the php.ini settings:

php -i | grep php.ini
@eleazarbr
eleazarbr / js-dynamic-keys.md
Created December 10, 2020 23:20
How do I create a dynamic key to be added to a JavaScript object variable

If you're able to use ES6 JavaScript features, you can use Computed Property Names to handle this very easily:

var key = 'DYNAMIC_KEY',
obj = {
  [key]: 'ES6!'
};

console.log(obj);
// > { 'DYNAMIC_KEY': 'ES6!' }
@eleazarbr
eleazarbr / length-js-object.md
Created December 10, 2020 17:26
Length of a JavaScript object
# indicate this is the root of the project
root = true
###########################################################
; common
###########################################################
[*]
charset = utf-8