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
@akuzemchak
akuzemchak / l4project.sh
Last active November 16, 2023 08:48
New L4 project with clean history
# Initial setup
git clone -o framework -b develop https://github.com/laravel/laravel.git project-name
cd project-name
git checkout --orphan master
git commit -m "Initial commit"
# Pulling changes
git fetch framework
git merge --squash -m "Upgrade Laravel" framework/develop
# Fix merge conflicts if any and commit
@akuzemchak
akuzemchak / DeployCommand.php
Created July 8, 2013 17:20
Basic Laravel deployment script
<?php
// app/commands/DeployCommand.php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class DeployCommand extends Command
{
@dhrrgn
dhrrgn / .gitattributes
Last active December 19, 2015 12:18
Stop hoping that other's core.autocrlf is set correctly. Add this .gitattributes to the root of your repo. Add any specific files to ensure Git doesn't try anything funny on you. If you think i missed a common extension, let me know in the comments. See here for more details: http://timclem.wordpress.com/2012/03/01/mind-the-end-of-your-line/
# Ensures all line endings are committed as LF, but will checkout with native line endings
* text=auto
# -- Override Section, just in-case Git tries to be sneaky
# Ensure that these files are recognized as text
*.asp text
*.aspx text
*.asx text
*.c text
@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:
*
<?php
$env = $app->detectEnvironment(function() {
return getenv('[APPNAME]_ENV') ?: 'development';
});

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;
@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';
@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')
@koomai
koomai / PhpStorm Keyboard Shortcuts.md
Last active May 25, 2024 01:05
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 / 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;