Skip to content

Instantly share code, notes, and snippets.

.wrapper{
width: 550px;
text-align: justify;
background: firebrick;
font-size: 0;
font-size: 12px\9; /* IE6-9 only hack */
}
.wrapper div{
background: white;

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@mrself
mrself / gulpfile.js
Last active August 29, 2015 14:20 — forked from ktmud/gulpfile.js
var BatchStream = require('batch-stream2')
var gulp = require('gulp')
var coffee = require('gulp-coffee')
var uglify = require('gulp-uglify')
var cssmin = require('gulp-minify-css')
var bower = require('gulp-bower-files')
var stylus = require('gulp-stylus')
var livereload = require('gulp-livereload')
var include = require('gulp-include')
var concat = require('gulp-concat')
(function($) {
$.parseQueryString = function(query) {
query = query || document.location.search;
if (!query) return null;
query = query.replace('?', '').split('&');
var i, part, property, val, params = {};
for (i = 0; i < query.length; i++) {
part = query[i].split('=');
property = part[0];
val = part[1];
// If you need chains
array.reduce(function(def, arrayItem) {
return def.then(function() {
// Access to arrayItem
// return $.get, $.post, $.ajax or another deferred
});
}, $.when()).done(function(){
// all deferred are completed
});
@mrself
mrself / nightwatch.sh
Last active March 26, 2018 09:51
Run nightwatch tests with manually started selenium server
#!/bin/bash
# It supposes you have bin directory in root project dir with `geckodriver` and `selenium-server-standalone-3.9.1.jar` files
# Create a log file for selenium
logfile="logs/selenium.log"
# Ensure a log file exists
if [ ! -e "$logfile" ] ; then
touch "$logfile"
fi
@mrself
mrself / run.sh
Created March 27, 2018 16:06
Create sublime link for windows
echo "c:\Program Files\Sublime Text 3\sublime_text.exe" %1 > %systemroot%\system32\subl.bat
@mrself
mrself / TestCase1.php
Last active March 29, 2018 10:44
Track errors in symfony when testing with phpunit when using WebTestCase
public function testSmth() {
$this->client = static::createClient();
$crawler = $this->client->request('GET', '/my-test-page');
if ($this->client->getResponse()->getStatusCode() !== 200) {
dump($crawler->filter('.text-exception')->first()->text());
dump($crawler->filter('.traces > li')->eq(0)->text());
dump($crawler->filter('.traces > li')->eq(1)->text());
throw new \Exception('Request to /my-test-page was not successfull');
}
@mrself
mrself / BaseEntity.php
Last active April 22, 2018 14:01
Set doctrine association
<?php
abstract class BaseEntity {
public function setAssoc($entityName) {
$inflector = ICanBoogie\Inflector::get();
$localProp = $inflector->pluralize($entityName);
foreach ($this->$localProp as $localAssocProp) {
$inParam = null;
foreach ($newAssocProps as $index => $item) {
@mrself
mrself / start.sh
Last active May 28, 2018 06:26
Set phpstorm debugging mode in console for windows
set XDEBUG_CONFIG="idekey=phpstorm"