Skip to content

Instantly share code, notes, and snippets.

rettal

Block or report user

Report or block rettal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View PHPUnit way to mock Doctrine2 Entity Manager.php
<?php
class AbstractManagerBase extends \PHPUnit_Framework_TestCase
{
protected function getEmMock()
{
$emMock = $this->getMock('\Doctrine\ORM\EntityManager',
array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
$emMock->expects($this->any())
->method('getRepository')
View pretty-json.php
<?php
/**
* Formats a JSON string for pretty printing
*
* @param string $json The JSON to make pretty
* @param bool $html Insert nonbreaking spaces and <br />s for tabs and linebreaks
* @return string The prettified output
* @author Jay Roberts
*/
View Avoid SSH Timeout Issues
sshd (the server) closes the connection if it doesn't hear anything from the client for a while.
You can tell your client to send a sign-of-life signal to the server once in a while.
The configuration for this is in the file ~/.ssh/config.
To send the signal every four minutes to remotehost, put the following in your ~/.ssh/config.
Host remotehost
HostName remotehost.com
View Unix-based SOCKS setup
First, protect the web interface port so that it cannot be accessed from the outside world.
You can use iptables to block the port as follows:
sudo iptables -A INPUT -i eth0 -p tcp --dport 8080 -j DROP
sudo iptables -I INPUT -i eth0 -s 127.0.0.1 -p tcp --dport 8080 -j ACCEPT
Note: You may have to replace eth0 and 8080 above if you are using another interface.
SOCKS proxy setup
Once you block the web interface port, the easiest way to access it is to use ssh to set up a socks proxy.
View PHP Syntax Highlighting in nano
nano /usr/share/nano/php.nanorc
syntax "php" "\.php|\.inc$"
color white start="<\?(php)?" end="\?>"
color magenta start="<[^\?]" end="[^\?]>"
color magenta "\$[a-zA-Z_0-9]*"
color brightblue "\->[a-zA-Z_0-9]*"
color cyan "(\[)|(\])"
color brightyellow "(var|class|function|echo|case|break|default|exit|switch|if|else|elseif|@|while|return|public|private|proteted|static)\s"
color brightyellow "\<(try|throw|catch|operator|new)\>"
View Searching in nano
Ctrl + W is the shortcut for searching. After entering the search term, press Enter.
To repeat the search, issue Alt + W. In this menu, you can select earlier searches using the arrow up/ down keys.
To toggle backwards searching, you need to press Alt + B in the search dialog.
For more shortcuts, press F1
View Remove Blank Lines in Notepad++
remove blank lines notepad++:
To get your lines not to be joined together you have to search for \r\n\r\n and replace with \r\n
View AngulaJS Filter Example
<!DOCTYPE html>
<html data-ng-app="DemoApp">
<head>
<meta charset="utf-8">
<body>
<div class="container" data-ng-controller="SimpleController">
Name:
<br />
<input type="text" data-ng-model="name" /> {{name}}
View Strip Spaces & Tabs in Javascrip
var str = '\n\n\n Multiline text\n with indentation\n damn.\n\n\n';
// remove first and last empty lines
str = str.replace(/^[\r\n]+|[\n\r]+$/gi, '');
var indentTab = str.match(/\t*/) != '',
indentSize = indentTab ? 1 : str.match(/\s*/)[0].length,
regex = new RegExp('^(?:' + (indentTab ? '\\t' : ' {' + indentSize + '}') + ')', 'mg');
// Remove indent
You can’t perform that action at this time.