Skip to content

Instantly share code, notes, and snippets.

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
<!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}}
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
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
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)\>"
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.
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
<?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
*/
<?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')
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.