Skip to content

Instantly share code, notes, and snippets.

View AdrianSchneider's full-sized avatar

Adrian Schneider AdrianSchneider

  • Kelowna, BC
View GitHub Profile
@AdrianSchneider
AdrianSchneider / cd
Created February 26, 2019 23:53
A smart keyword / search engine that gives you the "cd" (change directory) behaviour. Ex: CMD+L, then `cd ..` or `cd /`
javascript:window.location='%s' == '..' ? window.location.href.split('/').slice(0, -1).join('/') : "%s";
@AdrianSchneider
AdrianSchneider / dateperiod.test.php
Created January 7, 2014 00:31
DatePeriod woes PHP 5.5
<?php
$period = new DatePeriod(new DateTime, new DateInterval('P1M'), new DateTime('+1 year'));
var_dump($period); // shows public $interval
var_dump($period->interval); // new empty DateInterval object
var_dump($period->interval); // new empty DateInterval object
// $period->interval->m undefined
@AdrianSchneider
AdrianSchneider / next-port
Last active December 31, 2015 21:29
PHP built-in server on next unused port seq 8000 65000 defines the port range
#!/bin/sh
for port in $(seq 8000 65000); do echo -ne "\035" | telnet 127.0.0.1 $port > /dev/null 2>&1; [ $? -eq 1 ] && echo "$port" && break; done
<?php
$content = file_get_contents('/etc/hosts');
foreach (array_filter(explode("\n", $content)) as $line) {
$parts = preg_split('/\s+/', $line);
if (count($parts) < 2 or !preg_match('/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/', $parts[0])) {
continue;
}
list($ip, $hostName) = $parts;
public function editAction(Person $person, Request $request)
{
$form = $this->formFactory->create('person_edit', $person);
if ($request->getMethod() == 'POST') {
$form->bind($request);
if ($form->isValid()) {
$this->manager->update($person);
$this->flashes->add('success', 'Profile updated successfully.');

For some reason I'm getting an error when I try this... (first part)

output

Rewrite [hash....] (1/4)usage: git commit-tree <sha1> [(-p <sha1>)...] < changelog
could not write rewritten commit

pre-push script

git filter-branch --commit-filter /path/to/other/script

@AdrianSchneider
AdrianSchneider / Spaceless.php
Created September 28, 2011 16:55
Removes whitespace between HTML tags in PHP
$response = trim(preg_replace('/>\s+</', '><', $response));