Skip to content

Instantly share code, notes, and snippets.

View ilmoralito's full-sized avatar

Mario Martinez ilmoralito

View GitHub Profile
@ilmoralito
ilmoralito / async-await.js
Created October 10, 2017 04:45 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
Validation Errors and Rollback
A common use case is to rollback a transaction if there are validation errors. For example consider this service:
import grails.validation.ValidationException
class AuthorService {
void updateAge(id, int age) {
def author = Author.get(id)
author.age = age
if (!author.validate()) {
@ilmoralito
ilmoralito / gist:a7c61a4643333737855556816358feb3
Created June 3, 2018 04:04 — forked from wumpz/gist:5846559
list authors of a git repository including commit count and email
git shortlog -e -s -n
@ilmoralito
ilmoralito / php-pdo-mysql-crud.md
Created December 19, 2018 16:51 — forked from taniarascia/php-pdo-mysql-crud.md
Basic CRUD operations with PDO and MySQL

Basic CRUD operations with PDO

CRUD = Create, Read, Update, Delete

Open a database connection

$host = '127.0.0.1';
$dbname = 'test';
$username = 'root';
@ilmoralito
ilmoralito / 2018-https-localhost.md
Created August 29, 2019 04:29 — forked from cecilemuller/2019-https-localhost.md
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

@ilmoralito
ilmoralito / inline.groovy
Created September 22, 2019 18:46 — forked from kdabir/inline.groovy
Groovy List Destructuring
def (a,b,rest) = [0, 1, 2..-1].collect { [1,2,3,4][it] }
assert a == 1
assert b == 2
assert rest == [3,4]
@ilmoralito
ilmoralito / mime.html
Created November 8, 2020 06:13 — forked from topalex/mime.html
How to check real mime type of image in javascript
<html>
<head>
<script type="text/javascript" src="/jquery.min.js"></script>
<title>Mime type checker</title>
<script>
$(function () {
var result = $('div#result');
if (window.FileReader && window.Blob) {
$('span#submit').click(function () {
var files = $('input#file').get(0).files;
@ilmoralito
ilmoralito / mysql-docker.sh
Created August 17, 2021 18:52 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE