Skip to content

Instantly share code, notes, and snippets.

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 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 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 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 -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 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
View pretty-json.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 PHPUnit way to mock Doctrine2 Entity Manager.php
class AbstractManagerBase extends \PHPUnit_Framework_TestCase
protected function getEmMock()
$emMock = $this->getMock('\Doctrine\ORM\EntityManager',
array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
View D3 States
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
Code example explaining the enter, update and exit states in D3.
The 3 states basically define the actions that occur when data is added to a selection of elements.
Say if we were selecting data from a database where we had to perform a search with a query string,
each time we ran query the number of rows returned could be more, less, or could be the same but
contain different data, these in essence are the 3 states. more = enter, less = exit, same = update.
View Download CSV
public function downloadCsvAction()
$oldTimeLimit = ini_get('max_execution_time');
ini_set('max_execution_time', 60);
$lang = $this->params('lang', "en");
$this->setRatingsViewData($this->viewData, $lang);
$headers = array(
View chart.html
<div id="chart">
<h4>Percent of adults over 25 with at least a bachelor's degree:</h4>
<p><strong>Median:</strong> <span class="median"></span></p>
<small>Source: <cite><a href="">U.S. Census Bureau</a></cite>, via <cite><a href="">Census Reporter</a></cite></small>