Skip to content

Instantly share code, notes, and snippets.

@monkyz
monkyz / gist:3850614
Created October 8, 2012 03:45
silverstripe nginx vhost
# a better nginx config
02
# author @dnoiz1
03
04
server {
05
root /var/www/mysite.tld/;
06
@monkyz
monkyz / gist:3881752
Created October 12, 2012 21:50
error with mysql
hexdump sqldump.sql | head
0000000 6157 6e72 6e69 3a67 5420 6568 6f20 7470
0000010 6f69 206e 2d27 612d 6c6c 2027 7369 6420
0000020 7065 6572 6163 6574 2064 6e61 2064 6977
0000030 6c6c 6220 2065 6572 6f6d 6576 2064 6e69
0000040 6120 6620 7475 7275 2065 6572 656c 7361
0000050 2e65 5020 656c 7361 2065 7375 2065 2d2d
0000060 7263 6165 6574 6f2d 7470 6f69 736e 6920
0000070 736e 6574 6461 0a2e 2d2d 4d20 5379 4c51
0000080 6420 6d75 2070 3031 312e 2033 4420 7369
@monkyz
monkyz / gist:3886705
Created October 14, 2012 00:15
NPM commands guide (on going)
// uninstalling global packages(express in this example):
npm uninstall [pkg] -g
//view info about a certain package:
npm view [pkg]
//check globally installed npm modules
npm -g ls
@monkyz
monkyz / gist:3886998
Created October 14, 2012 02:04
installing nib
//first, require nib in the beginning of the file. note that requiring stylus was needed due to the second code change below:
, nib = require('nib')
, stylus = require('stylus');
//second change:
app.use(stylus.middleware({ src: __dirname + '/public',
compile: compile
}));
//third change, added the function compile:
@monkyz
monkyz / gist:3887131
Created October 14, 2012 03:24
coverting stylus to normal css syntax with colons, etc
/////////////////
// Semantic.gs // for Stylus: http://learnboost.github.com/stylus/
/////////////////
// Defaults which you can freely override
column-width = 60px
gutter-width = 20px
columns = 12
// Utility variable — you should never need to modify this
@monkyz
monkyz / gist:3888840
Created October 14, 2012 14:57
questions about stylus
if i have this:
body {
font: 14px/1.5 Helvetica, arial, sans-serif;
#logo {
border-radius: 5px;
}
}
would be the same as
@monkyz
monkyz / gist:3889223
Created October 14, 2012 17:15
stylus questions 2
body {
width: 100%;
clearfix();
}
@monkyz
monkyz / gist:3903538
Created October 17, 2012 03:26
better install stylus -g
npm install stylus -g
than after issue the following command:
stylus -w && nodemon app.js
http://learnboost.github.com/stylus/docs/executable.html
@monkyz
monkyz / gist:3903591
Created October 17, 2012 03:43
express.js security and general node.js security(on going)
Add app.enable('trust proxy') as I have express running behind nginx:
------------------------------------------------------------------------------------------------------------
Express behind proxies
Using Express behind a reverse proxy such as Varnish or Nginx is trivial, however it does require configuration. By enabling the "trust proxy" setting via app.enable('trust proxy'), Express will have knowledge that it's sitting behind a proxy and that the X-Forwarded-* header fields may be trusted, which otherwise may be easily spoofed.
Enabling this setting has several subtle effects. The first of which is that X-Forwarded-Proto may be set by the reverse proxy to tell the app that it is https or simply http. This value is reflected by req.protocol.
The second change this makes is the req.ip and req.ips values will be populated with X-Forwarded-For's list of addresses.
http://expressjs.com/guide.html
@monkyz
monkyz / gist:3909302
Created October 18, 2012 01:09
javascript cash register
var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item, quantity) {
switch (item) {
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;