Skip to content

Instantly share code, notes, and snippets.

View pajcho's full-sized avatar
:octocat:
Make it work, make it right, make it fast

Nikola Pajic pajcho

:octocat:
Make it work, make it right, make it fast
View GitHub Profile
@AshishDhamalaAD
AshishDhamalaAD / Merge specific files from one branch to another.md
Last active December 3, 2020 17:07
How to pick specific files from one branch and add it to another branch

Let's say there are two branches: master and feature-one.

There are some files that you want in the master branch from the feature-one branch but not all the files. Let's say those files are:

app/Models/User.php
app/Controllers/UsersController.php

You can accomplish that by doing the following:

Configure

xdebug.ini

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
@edouard-lopez
edouard-lopez / gulpfile.js
Created May 5, 2014 15:18
Gulp copy font-awesome files to dist/ directory
'use strict';
// Generated on 2014-04-14 using generator-leaflet 0.0.14
var gulp = require('gulp');
var open = require('open');
var wiredep = require('wiredep').stream;
// Load plugins
var $ = require('gulp-load-plugins')();
@dhrrgn
dhrrgn / benchmark.php
Last active August 29, 2015 14:00
Handy Benchmarking Function
<?php
function benchmark($name, $iterations, Closure $function)
{
echo "Starting Benchmark: {$name} (".number_format($iterations)." Iterations)\n";
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$function();
}
$elapsed = microtime(true) - $start;
@koomai
koomai / PhpStorm Keyboard Shortcuts.md
Last active October 13, 2023 00:11
Frequently Used PhpStorm Keyboard Shortcuts

Note: Some of these shortcuts have been remapped for my own convenience (Preferences->Keymap). These are Mac shortcuts, just use the Windows/Linux equivalent of the Cmd/Option/Ctrl/Del keys.

####Search, Go to, Navigation ####

Cmd + P - Search file

Cmd + Shift + O - Search everywhere

(I swapped the above two recently because I use Cmd + P to search for files most of the time).

@dhrrgn
dhrrgn / functions.php
Created March 3, 2014 16:02
Slugify. Note: Requires PHP >= 5.4 and the Intl extension
<?php
function slugify($string, $toLower = true) {
$rules = "Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove;";
if ($toLower) {
$rules .= ' Lower();';
}
$string = transliterator_transliterate($rules, $string);
// Remove repeating hyphens and spaces (e.g. 'foo---bar' becomes 'foo-bar')
@danharper
danharper / a-FormatController.php
Last active August 1, 2017 12:06
A Laravel Controller which allows you to display API/report data in multiple formats. For example, you may display a preview as HTML, and offer buttons to download as CSV and JSON.
<?php
// this is the base controller which parses output to HTML/CSV/JSON depending on the format in the URL
use Illuminate\Support\Collection;
class FormatController extends Controller {
protected $fileName = 'export';
protected $view = 'reports.output';

My Validation Base Class

I was asked how I deal with validation / create and update validation rulesets. Well here is one method I have used. Don't be afraid to build on top of what the framework has already given you. In my projects I use a base class for almost anything. You never know when you want your classes to inherit some common functionality. My BaseValidator actually has some pretty useful methods and properties in it.

<?php

namespace FooProject\Internal\Validators;

use FooProject\Internal\Sanitizers\BaseSanitizer;
<?php
$env = $app->detectEnvironment(function() {
return getenv('[APPNAME]_ENV') ?: 'development';
});
@dhrrgn
dhrrgn / paths.php
Last active December 20, 2015 09:08
A few handy functions for dealing with paths in PHP in a cross-platform environment.
<?php
if ( ! defined('IS_WIN')) {
define('IS_WIN', (DIRECTORY_SEPARATOR === '\\'));
}
/**
* Normalizes and joins path segments in accordance with the current OS standard.
*
* Usage:
*