Skip to content

Instantly share code, notes, and snippets.

View yuchen's full-sized avatar
🌴
On vacation

clark yuchen

🌴
On vacation
  • china, shanghai
  • 01:12 (UTC +08:00)
View GitHub Profile
<?php
/**
* LDAP PHP Change Password Webpage
* @author: Matt Rude <http://mattrude.com>
* @website: http://technology.mattrude.com/2010/11/ldap-php-change-password-webpage/
*
*
* GNU GENERAL PUBLIC LICENSE
* Version 2, June 1991

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

# Aliasses
Set-Alias l ls
Set-Alias e explorer
# Force coloring of git and npm commands
$env:TERM = 'cygwin' # windows-ansi | cygwin
$env:LESS = 'FRSX'
#
# Custom prompt
@yuchen
yuchen / app.js
Created August 20, 2014 01:07 — forked from branneman/app.js
#!/usr/bin/env node
'use strict';
var spawn = require('child_process').spawn;
var args = [
'--harmony',
'app/bootstrap.js'
];
//
// SVG — hasClass, addClass, removeClass, toggleClass
// Source:
// https://gist.github.com/branneman/8436956
// Taken and adapted from:
// http://toddmotto.com/hacking-svg-traversing-with-ease-addclass-removeclass-toggleclass-functions/
//
if (SVGElement && SVGElement.prototype) {
//
// Articles controller
// Optional module description line.
//
'use strict';
var fs = require('fs');
var path = require('path');
/**
* Strict mode
* Opt in to a restricted variant of JavaScript.
*/
'use strict';
(function() { 'use strict'; });
/**
* Array.prototype.forEach()
* Executes a provided function once per array element.
@yuchen
yuchen / dump.php
Created August 20, 2014 01:08 — forked from branneman/dump.php
function dump($var) {
ob_start();
var_dump($var);
$output = ob_get_clean();
echo preg_replace("/=>(\s+)/m", ' => ', $output);
}
@yuchen
yuchen / event.js
Created August 20, 2014 01:08 — forked from branneman/event.js
$(function() {
var resizeEnd;
$(window).on('resize', function() {
clearTimeout(resizeEnd);
resizeEnd = setTimeout(function() {
$(window).trigger('resizeEnd');
@yuchen
yuchen / server.js
Created August 20, 2014 01:08 — forked from branneman/server.js
var fs = require('fs'),
exec = require('child_process').exec,
express = require('express'),
app = express();
app.get('/static/img/*.svg.*.png', function(req, res) {
var pngFile = 'src' + req.url,
svgFile = pngFile.substring(0, pngFile.indexOf('.svg') + 4);
if (!fs.existsSync(svgFile)) {
return res.render('404', {