Skip to content

Instantly share code, notes, and snippets.

View shiawuen's full-sized avatar

Tan Shiaw Uen shiawuen

View GitHub Profile
@shiawuen
shiawuen / depot.add.js
Created March 17, 2011 03:56
Problem with using Depot.add, callback never get trigger and the line after the add never get executed. Failed silently…
var db = new Mojo.Depot(
{ name: 'my_wordpress_db', version: 1, estimatedSize: 25000, replace: false },
function() { Mojo.Log.info('Success'); },
function(error) { Mojo.Log.warn('Unable to open database (#' +error+ ')' ); }
);
// NOT WORKING
db.add(
'address', 'address',
function(){ Mojo.Log.info('Address Added'); },
@shiawuen
shiawuen / path.js
Created September 1, 2011 17:46
prevent access /etc/passwd
var path = require('path')
var userPath = path.normalize('/var/www/app/abc/../../../../../../../../../../etc/passwd')
if (userPath.indexOf(__dirname) == 0 ) {
// Valid path
} else {
// Invalid path
}
@shiawuen
shiawuen / crunchbase-api-v1.md
Created November 22, 2011 14:52 — forked from dominicsayers/crunchbase-api-v1.md
CrunchBase API v1

NOTE: This documentation has been put here because I couldn't find it anywhere else. I am not associated with Crunchbase in any way. I cannot help you with your Crunchbase API problems. If you need help try here: https://groups.google.com/forum/#!forum/crunchbase-api

CrunchBase API v1 Documentation

Overview

The CrunchBase API provides JSON representations of the data found on CrunchBase. The API currently supports three actions: "show", "search", and "list", which are each described below.

@shiawuen
shiawuen / index.html
Created December 29, 2011 15:05
Sample to upload file by chunk
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>test upload by chunk</title>
</head>
<body>
<input type="file" id="f" />
<script src="script.js"></script>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Combination – slooow way</title>
</head>
<body>
<script src="index.js"></script>
</body>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Combination – stupid way</title>
</head>
<body>
<script src="index.js"></script>
</body>
var userSchema = new Schema({
email: String
, passwordHash: String
});
userSchema.pre('validate', function(next) {
if (this.password === this.passwordConfirm) {
this.set('passwordHash', hash(this.password);
@shiawuen
shiawuen / index.js
Created January 30, 2012 19:57
Was trying to query products based on id passed in, but I got all of the records instead of the one with category id given
var Product = new Schema({
quantity: { type: Number }
, title: { type: String, trim: true }
, category: { type: ObjectId, ref: 'Category' }
})
var Model = db.model('Product', Product);
@shiawuen
shiawuen / app.js
Created January 30, 2012 21:03
Async dynamic helper for Express
var yourAsyncDynamicHelper = require('./yourAsyncDynamicHelper')
app.configure(function(){
//
// other middlewares
//
app.use(yourAsyncDynamicHelper());
//
// ....
app.configure(function() {
// ....
app.set('views', __dirname + '/public');
app.set('view options', { layout: false });
app.register('.html', {
compile: function(str, options){