Skip to content

Instantly share code, notes, and snippets.

View hugopereira84's full-sized avatar

Hugo Pereira hugopereira84

View GitHub Profile
@hugopereira84
hugopereira84 / 0_reuse_code.js
Last active August 29, 2015 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@hugopereira84
hugopereira84 / mysql_db_tables.mysql
Last active August 29, 2015 14:18
Determining the number of tables that are contained in a MySQL database is very straight-forward, although it is an often asked question. The simplest way to accomplish this is using the following SQL query. In this query, you will provide the database, and the SQL will access MySQL’s internal data scheme (information_schema).
SELECT count(*) as 'Tables', table_schema as 'Database'
FROM information_schema.TABLES
WHERE table_schema= 'spendanalysis'
GROUP BY table_schema
@hugopereira84
hugopereira84 / netbeans_xdebug
Last active August 29, 2015 14:18
Configure netbeans with xdebug and plugins
Source: http://articlebin.michaelmilette.com/making-xdebug-work-with-netbeans-on-windows/
----------------------------------------
Step 1 -- Configure PHP to work with XDEBUG
Modify your php.ini file. Start by commenting out anything that refers to ZEND… by adding a semi-colon in front (to the left) of the line. Zend is not compatible with XDEBUG.
Next comment out everything under the [xdebug] section. Then add the following, making sure to modify the lines that refer to your XAMPP path (doesn't work with the Lite version).
Common scenario: it is the beginning of a new project, you create a new virtualhost in your webserver, record newproject.local into your hosts file, so the address resolves to your local machine, restart webserver, test. Is there an easier way? Yes, it is possible to spare the part where you edit the hosts file.
The title of the post is partly a google bait, because wildcards are not possible in the hosts file, sorry about that. But, there is still way however, to get rid of editing that file, alltogether. What you need is a DNS server on the network somewhere, that you can configure, or, you could just install one on your own machine locally. Which one to choose depends on what you need. If you need to have some “in house” addresses, that resolve for everyone on the network, install it on a PC that everyone can access. If you just want to spare editing your own hosts file every time you start a new project, install it locally.
This post will cover installing dnsmasq locally, and setting up your linux PC to
@hugopereira84
hugopereira84 / Info.txt
Last active August 29, 2015 14:19
How to gracefully handle files that exceed PHP's `post_max_size`
There is a way to catch / handle files exceeding max post size, this is my preferred on, as it tells the end user what has happened and who is at fault ;)
@hugopereira84
hugopereira84 / php_analyze
Last active October 27, 2015 09:28
10 Best PHP Tools for Analyzing and Parsing PHP Code (original post link: http://codegeekz.com/10-best-php-tools-for-analyzing-and-parsing-php-code/)
1. PHPMD (http://phpmd.org/)
PHPMD is an easy to configure, user-friendly front-end for the raw metrics that PHP Depend measures. It looks for several potential problems in your code, including possible bugs, suboptimal code, unused parameters, and more.
2. PHPCPD (https://github.com/sebastianbergmann/phpcpd)
PHPCPD is a Copy/Paste Detector (CPD) for PHP code. If you have to start working on a big project that’s been either abandoned before or follows an old way of programming, then this is the one tool to help you analyze code to avoid having repetitive functions and calls all over your code base. It’s easy to setup and can analyze a project as big as WordPress in less than a minute.
3. Parsedown (http://parsedown.org/)
Parsedown is a Markdown parser built with PHP to include in your apps. It’s fast and consistent, uses GitHub-flavored Markdown, and offers a Markdown Extra extension.
To use Traits, you need to be using PHP >=5.4.
More info.: http://stackoverflow.com/questions/9205083/php-traits-vs-interfaces
This is an example of how a trait works, taken straight from the docs;
<?php
class Base {
public function sayHello() {
echo 'Hello ';
@hugopereira84
hugopereira84 / svn
Created May 4, 2015 08:46
SVN Helper
Checkout svn:
svn+ssh://pathToFolder/
CheckOut Svn, para criar estrutura de um projecto de raiz:
svn co svn+ssh://pathToFolder/home/svn/repositories/ . --username nameOfUser
@hugopereira84
hugopereira84 / info.md
Last active August 29, 2015 14:21
Git Commit messages

Git Commit Messages

Use the present tense ("Add feature" not "Added feature") Use the imperative mood ("Move cursor to..." not "Moves cursor to...") Limit the first line to 72 characters or less Reference issues and pull requests liberally

Consider starting the commit message with an applicable emoji: :art: :art: when improving the format/structure of the code :racehorse: :racehorse: when improving performance

@hugopereira84
hugopereira84 / case-sensitive-query
Last active September 19, 2016 10:48
Tips Mysql
Make a case-sensitive query
----------
One way:
SELECT * FROM `table` WHERE BINARY like '%value%'
Other way:
SELECT * FROM `table` WHERE `column` like '%value%' COLLATE utf8_bin