Skip to content

Instantly share code, notes, and snippets.

View dgoguerra's full-sized avatar

Diego Guerra dgoguerra

View GitHub Profile
@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 / 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);
<!DOCTYPE html>
<html lang="en">
<head>
<link href="lib/bootstrap.css" rel="stylesheet">
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/bootstrap.js"></script>
</head>
@dgoguerra
dgoguerra / www-data-permissions.md
Last active August 29, 2015 14:00
/var/www proper permissions

Add your user to www-data group.

sudo adduser USERNAME www-data

Then, change recursively the ownership of /var/www to your username.

sudo chown USERNAME:www-data -R /var/www
@dgoguerra
dgoguerra / .bash_profile
Last active April 17, 2019 19:40
My dotfiles (.gitconfig with git aliases, .bash_profile, etc.). Old! Now at: https://github.com/dgoguerra/dotfiles
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export HISTCONTROL=ignorespace
# http://unix.stackexchange.com/a/81699
alias wanip='dig +short myip.opendns.com @resolver1.opendns.com'
# http://stackoverflow.com/a/13322549
alias lanip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
@dgoguerra
dgoguerra / script-with-options.sh
Last active November 10, 2024 20:00
Manual alternative to getopt in bash scripts, supporting short and long options
#!/usr/bin/env bash
# File name
readonly PROGNAME=$(basename $0)
# File name, without the extension
readonly PROGBASENAME=${PROGNAME%.*}
# File directory
readonly PROGDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# Arguments
readonly ARGS="$@"
@dgoguerra
dgoguerra / node-npm-install.sh
Last active January 11, 2016 13:07
Install nodejs and npm latest versions; needs sudo rights
# C++ needed to compile node
# sudo apt-get -y install build-essential
cd /tmp
wget --no-verbose http://nodejs.org/dist/node-latest.tar.gz
tar zxf node-latest.tar.gz
cd node-v*
./configure && make && sudo make install
@dgoguerra
dgoguerra / coredump.md
Last active August 29, 2015 13:56
Generating and viewing core dumps

Enable generating core dumps

The configuration file /proc/sys/kernel/core_pattern defines the default behaviour when a crash occurs. If it contains a single word such as core, a core dump will be generated on the current directory with that name. If the first character of its content is |, then the core file will be piped to a process, such as Apport (|/usr/share/apport/apport %p %s %c).

To enable core dumps for your current terminal session ignoring the default action:

ulimit -c unlimited
@dgoguerra
dgoguerra / debugging.md
Created January 28, 2014 09:49
Valgrind debugging notes

Remote debugging with GDB and Valgrind

First, Valgrind starts the program to debug:

$ valgrind --vgdb=yes --vgdb-error=0 [valgrind-options] [program] [program-options]

It will halt until GDB is hooked to the process, from another terminal:

@dgoguerra
dgoguerra / p4merge-git-tool.md
Last active December 23, 2024 11:56
Setup p4merge as difftool and mergetool on Windows

Setting up p4merge as diff and merge tool on Windows. Tried for Git version 1.8.4.msysgit.0.

Two alternatives are explained: using the command line, and directly editing the config file.

Setting up from the command line

Being the installation path "C:Program Files\Perforce\p4merge.exe", just run:

$ git config --global diff.tool p4merge