Skip to content

Instantly share code, notes, and snippets.

@przor3n
przor3n / gist:7e6e864f8a5d396115f8
Created December 14, 2015 13:39
Redirect to route in routes.yml
SomeRoute:
pattern: /someroute
defaults:
_controller: SomeBundle:Controller:action
AnotherRoute:
pattern: /anotherroute
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: SomeRoute
@przor3n
przor3n / gist:0268724892b81bac1cbd
Created January 4, 2016 15:12
yield and iterator_to_array as a dynamic generator
private function getSearchTypeList()
{
foreach ($this->choices as $choice) {
yield $choice => 'type.' . $choice;
}
}
//then
iterator_to_array($this->getSearchTypeList())
@przor3n
przor3n / gist:beb98100d8e618c698af
Created January 6, 2016 20:01
Git - ignore local files
The .git/info/exclude file has the same format as any .gitignore file. Another option is to set core.excludesFile to the name of a file containing global patterns.
Note, if you already have unstaged changes you must run the following after editing your ignore-patterns:
git update-index --assume-unchanged [<file>...]
Note on $GIT_DIR: This is a notation used all over the git manual simply to indicate the path to the git repository. If the environment variable is set, then it will override the location of whichever repo you're in, which probably isn't what you want.
Link: http://stackoverflow.com/questions/1753070/git-ignore-files-only-locally
@przor3n
przor3n / gist:c048015a9ff625a08a81
Created January 7, 2016 09:45
Year range for select
'years' => range(date('Y'), 2014)
class InvalidRowException extends \Exception
{
public static function incorrectColumns(Row $row) {
return new static("Row #" . $row->getIndex() . " is missing one or more columns");
}
}
if (!$row->hasColumns($expectedColumns)) {
throw InvalidRowException::incorrectColumns($row);
}
@przor3n
przor3n / gist:1bab6ff1235849da8693
Created March 23, 2016 15:41
Git reset local branch to remote
git fetch origin
git reset --hard origin/master
git checkout develop
git pull
git checkout branch #co by zapisać
git fetch develop
git rebase upstream/develop develop #tutaj sobie cofamy
@przor3n
przor3n / wordpress-snips.php
Created February 13, 2017 22:22
Wordpress snips
<?php
function removeShit()
{
global $wpdb;
$posts = $wpdb->get_results("
SELECT wp.ID, wp.post_content FROM wp_posts wp, novationstudio_events_event e WHERE wp.post_title = e.title;
");
foreach($posts as $post) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node) {
// You can get nid and anything else you need from the node object.
$nid = $node->id();
}
function generate_random($string) {
$charactersLength = strlen($string);
$randomString = '';
for ($i = 0; $i < $charactersLength; $i++) {
$randomString .= $string[rand(0, $charactersLength - 1)];
}
return $randomString;
}