Skip to content

Instantly share code, notes, and snippets.

View dhargitai's full-sized avatar
💭
Everything is awesome 😎

David Lush dhargitai

💭
Everything is awesome 😎
View GitHub Profile
@dhargitai
dhargitai / phpunit-report-runtime.sh
Created October 29, 2014 13:24
Prints the 15 slowest unit tests
alias phpunit-report-runtime="bin/phpunit --log-json php://stdout \
| awk '\$NF ~ '/,/' && \$1 ~ /\"(test|time)\"/' \
| cut -d: -f2- \
| sed \"N;s/\n/--/\" \
| sed \"s/,//\" \
| awk 'BEGIN{FS=\"--\"}; {print \$2 \$1}' | sort -gr \
| head -n 15"
@dhargitai
dhargitai / composerOauthToken.md
Last active November 9, 2024 22:29
Stop Composer asking for GitHub credentials

Because of GitHub's rate limits on their API it can happen that Composer prompts for authentication asking your username and password so it can go ahead with its work.

If you would prefer not to provide your GitHub credentials to Composer you can manually create a token using the following procedure:

Create an OAuth token on GitHub.

Add it to the configuration running composer config -g github-oauth.github.com <oauthtoken>

Now Composer should install/update without asking for authentication.

For anyone else who wants to set Eclipse style goto definition, you need to create .sublime-mousemap file in Sublime User folder.
Windows - create Default (Windows).sublime-mousemap in %appdata%\Sublime Text 3\Packages\User
Linux - create Default (Linux).sublime-mousemap in ~/.config/sublime-text-3/Packages/User
Mac - create Default (OSX).sublime-mousemap in ~/Library/Application Support/Sublime Text 3/Packages/User
Now open that file and put the following configuration inside
@dhargitai
dhargitai / Remote connect to MySQL database in Vagrant VM
Last active August 29, 2015 14:03
Make sure you have these settings to be able to connect remotely (i.e. with MySQL Workbench of Sequel Pro) to your MySQL database in a Vagrant VM.
Don't run the mysql deamon with --skip-networking option and don't restrict it to
allow connections only from the VM. In order to do that, comment out
bind-address SOME-IP-ADDRESS
settings in /etc/my.cnf, or bind your host machine's IP address too.
Grant all privileges for the root user in mysql:
GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'root';
GRANT ALL ON *.* TO root@'localhost' IDENTIFIED BY 'root';
Enable port forwarding in /etc/ssh/sshd_config:
@dhargitai
dhargitai / makeScreenshotOnFailure
Created June 10, 2014 09:34
With this Behat function you can create a screenshot when a test fails.
<?php
/**
* @AfterStep
*/
public function makeScreenshotOnFailure($event)
{
if (StepEvent::FAILED !== $event->getResult() || !($this->getSession()->getDriver() instanceof Selenium2Driver)) {
return;
}
@dhargitai
dhargitai / Magento Subscriber Import From CSV
Created June 9, 2014 09:30
Import newsletter subscribers into Magento
<?php
$magentoRootPath = './public';
require_once $magentoRootPath . '/shell/abstract.php';
class SubscriberImportFromCsv extends Mage_Shell_Abstract
{
protected $_fileName;
protected $_emailFieldIndex;
protected $_hasHeaderRow;
@dhargitai
dhargitai / Magento Customer Importer
Last active May 5, 2016 12:23
Import customers into Magento from command line using a CSV file
<?php
define('BUNCH_SIZE_TO_INSERT', 20);
$magentoRootPath = './public';
require_once $magentoRootPath . '/shell/abstract.php';
class CustomerImportFromCsv extends Mage_Shell_Abstract
{
protected $_headerArray = array();
@dhargitai
dhargitai / Invalid email CSV filter
Last active August 29, 2015 14:02
Filter rows with invalid emails from CSV file
<?php
function filterRowsWithInvalidEmailsInCsv($fileName, $emailFieldIndex, $hasHeaderRow)
{
if (($handle = fopen("{$fileName}.csv", "r")) !== FALSE) {
$existingEmails = array();
$count = 0;
$filteredCsvFile = fopen("{$fileName}_filtered.csv", 'w');
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// for debug : trace every event
/*var originalTrigger = wp.media.view.MediaFrame.Post.prototype.trigger;
wp.media.view.MediaFrame.Post.prototype.trigger = function(){
console.log('Event Triggered:', arguments);
originalTrigger.apply(this, Array.prototype.slice.call(arguments));
}*/
// custom state : this controller contains your application logic
wp.media.controller.Custom = wp.media.controller.State.extend({
@dhargitai
dhargitai / jQuery definition
Created May 26, 2014 05:27
Define jQuery the right way
(function($) {
$(document).ready(function() {
});
})(jQuery);