Skip to content

Instantly share code, notes, and snippets.

View tbergeron's full-sized avatar
😠
Microsoft's acquisition of GitHub won't change a thing? Oh dear irony.

Tommy Bergeron tbergeron

😠
Microsoft's acquisition of GitHub won't change a thing? Oh dear irony.
View GitHub Profile
@tbergeron
tbergeron / gist:2251869
Created March 30, 2012 14:21
JSON validation proof of concept
// receives: { name: [ { minimumLength: 5 } ] }
// fetches field's validations and uses validators
// todo: maybe find a way to do so without as many for?
function validateField(fieldValidations) {
for (fieldName in fieldValidations) {
for (validatorIndex in fieldValidations[fieldName]) {
for (validator in fieldValidations[fieldName][validatorIndex]) {
useValidator(validator, fieldValidations[fieldName][validatorIndex][validator]);
}
@tbergeron
tbergeron / gist:2344150
Created April 9, 2012 15:11
Raynos pd/mongodb result example
{ db:
{ databaseName: 'thinair',
serverConfig:
{ host: 'my.fantastic.host.com',
port: 27017,
options: [Object],
internalMaster: true,
connected: true,
poolSize: 4,
ssl: false,
@tbergeron
tbergeron / gist:2353179
Created April 10, 2012 17:42
how to properly handle helpers
var helpers = require('../helpers');
if (helpers.is_post(req)) {
this.Projects.byCode(req.params.project_code, function(project) {
if (!project) {
require('../helpers').flash(req, 'error', 'Unable to find project.');
res.redirect('/projects');
}
});
}
@tbergeron
tbergeron / gist:2587905
Created May 3, 2012 18:25
Utilisation de la même valeur mais pas du même UoM, mais donne le bon UoM avec la... même valeur?!
' Utilisation de OrderQtyUoMCode (25 => kg)
.AddColumnTemplate(New ViewTemplateColumn("OrderQty", Languages.Translate(Rsx.DBColumnRsx, "WeightOrder"), 25, iIndex.NextValue, False, False, ViewTemplateColumn.ColumnFormat.Numeric, DataFormat.GetNumericMask(6, 4, True)) With {.ColumnEdit = New SixIRepositoryTextBoxNumeric(6, 4, True)})
.AddColumnTemplate(New ViewTemplateColumn("OrderQtyUoMCode", Languages.Translate(Rsx.DBColumnRsx, "WeightUoM"), 25, iIndex.NextValue, False, False))
.AddColumnTemplate(New ViewTemplateColumnMultiField(ViewTemplateColumnMultiField.ColumnMergeType.ValueWithUoM, " ", {"OrderQty", "OrderQtyUoMCode"}.ToList) With {.Caption = Translate(Rsx.DBColumnRsx, "WeightOrder"), .IsVisible = True, .ShowInColumnChooser = True, .VisibleIndex = iIndex.NextValue, .Width = 25, .ColumnNameSortGroup = "WeightOrder", .Alignment = ViewTemplateColumn.ColumnAlignement.AlignFar})
' Donne par exemple: 952.56kg
' --------
function xhr(options, callback) {
var xhr = new XMLHttpRequest(),
method = options.method || 'get';
xhr.onreadystatechange = function() {
if (this.readyState === 4) {
callback(this.response || this.responseText || this.responseXML);
}
}
// getByCode is now availaible from the client!
socket.on('getByCode', function (code, callback) {
getByCode(code, function(project){
callback(project);
})
});
// gets a project by its code
getByCode: function(code, callback) {
this.baseFindOne({ code: code }, function(project) {
return callback(project ? project : null);
module.exports = {
io: null,
initialize: function(server) {
this.io = require('socket.io').listen(server);
this.io.sockets.on('connection', function(socket) {
// how to inject stuff here?
});
},
module.exports = {
io: null,
socket: null,
initialize: function(server) {
console.log("initialized!");
this.io = require('socket.io').listen(server);
var that = this;
module.exports = {
io: null,
socket: null,
createReactiveMethod: null,
initialize: function(server) {
console.log("initialized!");
this.io = require('socket.io').listen(server);
var that = this;
@tbergeron
tbergeron / gist:2841666
Created May 31, 2012 07:28
Parse Quick Data Handling Model
var Model = function(name) {
this.ModelName = name;
this.Model = Parse.Object.extend(this.ModelName);
this.ModelInstance = new this.Model();
this.getList = function(callback){
var query = new Parse.Query(this.Model);
query.find({
success: function(results) {
callback(results);