Skip to content

Instantly share code, notes, and snippets.

@Idered
Idered / script.js
Created January 5, 2014 04:41
Remove first and last empty lines, remove useless indentation. Good for parsing HTML
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
@wowo
wowo / PHPUnit way to mock Doctrine2 Entity Manager.php
Created November 1, 2011 20:22
PHPUnit's 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);
$emMock->expects($this->any())
->method('getRepository')
@ralphschindler
ralphschindler / example.php
Created October 24, 2012 23:18
Zend\Db\Sql\Select example usage
<?php
use Zend\Db\Sql\Select;
// basic table
$select0 = new Select;
$select0->from('foo');
// 'SELECT "foo".* FROM "foo"';
@DanHerbert
DanHerbert / fix-homebrew-npm.md
Last active February 12, 2024 17:18
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

OBSOLETE

This entire guide is based on an old version of Homebrew/Node and no longer applies. It was only ever intended to fix a specific error message which has since been fixed. I've kept it here for historical purposes, but it should no longer be used. Homebrew maintainers have fixed things and the options mentioned don't exist and won't work.

I still believe it is better to manually install npm separately since having a generic package manager maintain another package manager is a bad idea, but the instructions below don't explain how to do that.

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

@ircmaxell
ircmaxell / Expressions.php
Created September 21, 2011 16:51
A math parser and evaluator implementation
<?php
class Parenthesis extends TerminalExpression {
protected $precidence = 6;
public function operate(Stack $stack) {
}
public function getPrecidence() {
return $this->precidence;
@paulirish
paulirish / bling.js
Last active February 20, 2024 14:11
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;