Skip to content

Instantly share code, notes, and snippets.

View dgoguerra's full-sized avatar

Diego Guerra dgoguerra

View GitHub Profile
@dgoguerra
dgoguerra / json_indent.php
Created August 26, 2014 16:47
json prettify in PHP
/**
* Indents a flat JSON string to make it more human-readable.
*
* http://www.daveperrett.com/articles/2008/03/11/format-json-with-php/
*/
function json_indent($json)
{
$result = '';
$pos = 0;
$strLen = strlen($json);
@dgoguerra
dgoguerra / yii2-webapp-installation.md
Last active July 24, 2023 07:28
Setup steps to serve a Yii 2 webapp in an Amazon EC2 instance with Ubuntu 14.04.

Installation

This file covers all the steps needed to install a web server and Yii 2 framework to host a project in an Ubuntu 14.04 server.

Apache and php installation

First, the packages related to apache and php need to be installed:

@dgoguerra
dgoguerra / vhost.py
Last active August 29, 2015 14:08 — forked from fideloper/vhost.py
#! /usr/bin/python
from sys import argv
from os.path import exists
from os import makedirs
from os import symlink
from os import system
import getopt
#
@dgoguerra
dgoguerra / aws-s3api.sh
Last active May 20, 2016 10:21
Obtain an AWS S3 bucket size
bucket_name="BUCKET_NAME"
aws s3api list-objects \
--bucket $bucket_name \
--region `aws s3api get-bucket-location --bucket $bucket_name --output text` \
--output json \
--query "[sum(Contents[].Size), length(Contents[])]"
@dgoguerra
dgoguerra / mysql_tables_size.sql
Last active November 24, 2016 13:11
MySQL tables size
-- From: http://stackoverflow.com/a/9620273
-- Change 'SCHEMA_NAME_HERE'
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = 'SCHEMA_NAME_HERE'
ORDER BY (data_length + index_length) DESC;
@dgoguerra
dgoguerra / get_nested_obj_property.js
Created May 10, 2015 18:27
Access a nested object property using a string with Lodash / Underscore (or another implementation of the reduce() function)
function getObjProperty(containerObj, str, defaultValueArg) {
var defaultValue = typeof defaultValueArg !== 'undefined' ? defaultValueArg : null;
try {
return _(str.split('.')).reduce(function(obj, key) {
return obj[key];
}, containerObj);
} catch (e) {
return defaultValue;
}
@dgoguerra
dgoguerra / ngrok.md
Last active August 29, 2015 14:21
ngrok notes

Open an HTTP tunnel to localhost

To open an HTTP tunnel to localhost on port 80:

ngrok http 80

If the forwarding setup is http://1d3a3ba5.ngrok.io -> localhost:80, access it with the URL http://1d3a3ba5.ngrok.io.

@dgoguerra
dgoguerra / mysql-dump-s3.sh
Last active February 8, 2016 14:04
Dump a MySQL database and upload the compressed output to S3
#!/bin/bash
# File name
readonly PROGNAME=$(basename $0)
# File name, without the extension
readonly PROGBASENAME=${PROGNAME%.*}
# Arguments
readonly ARGS="$@"
# Arguments number
readonly ARGNUM="$#"
// autoclick the correct squares at 1/10 of a sec...
var interval = setInterval(function() { $('iframe').contents().find('.thechosenone').click(); }, 100);
// stop whenever you want!
clearInterval(interval);
@dgoguerra
dgoguerra / readme.md
Last active August 29, 2015 14:25 — forked from coolaj86/how-to-publish-to-npm.md
NPM publishing notes

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser