Skip to content

Instantly share code, notes, and snippets.

View shiawuen's full-sized avatar

Tan Shiaw Uen shiawuen

View GitHub Profile
@shiawuen
shiawuen / call-method.js
Created March 6, 2012 02:15
Can instance methods not be called from within other instance methods?
var goose = require('mongoose')
, db = goose.connect('mongodb://localhost/testmongo')
, Schema = goose.Schema
, sc = new Schema({
a: String,
b: Date
})
sc.methods.bbb = function() {
return this.b.getFullYear()
@shiawuen
shiawuen / securing_rails_updates.md
Created March 5, 2012 15:54 — forked from peternixey/securing_rails_updates.md
How Homakov hacked GitHub and how to protect your application

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr.


@homakov’s explot on GitHub was simple and straightforward. Calling it an attack makes it sound malicious whereas the truth was that GitHub bolted its front door but left the hinges on quick release. Homakov released the hinges, walked in and shouted to anyone who would listen that they had a problem.

app.get('/path/to/html.html', function(req, res, next) {
console.log('oh hai!');
// The request will then pass down to the static file middleware
next();
});
// ....
app.configure(function() {
// ....
app.set('views', __dirname + '/public');
app.set('view options', { layout: false });
app.register('.html', {
compile: function(str, options){
@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());
//
@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);
var userSchema = new Schema({
email: String
, passwordHash: String
});
userSchema.pre('validate', function(next) {
if (this.password === this.passwordConfirm) {
this.set('passwordHash', hash(this.password);
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Combination – stupid way</title>
</head>
<body>
<script src="index.js"></script>
</body>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Combination – slooow way</title>
</head>
<body>
<script src="index.js"></script>
</body>
@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>