Skip to content

Instantly share code, notes, and snippets.

View miguelludert's full-sized avatar

Miguel Ludert miguelludert

View GitHub Profile
@miguelludert
miguelludert / when.js
Created July 29, 2014 14:57
mpromise when
var mongoose = require('mongoose');
var Deferred = require("JQDeferred");
var _ = require("lodash");
function when() {
var arrayOfPromises = _.isArray(arguments[0]) ? arguments[0] : arguments;
var dfds = _.map(arrayOfPromises,function(promise){
var dfd = new Deferred();
@miguelludert
miguelludert / fromJS
Last active August 29, 2015 14:17
rockout fromJS
ko.rockout.fromJS = function fromJS(target) {
target = ko.toJS(target);
if (_.isPlainObject(target)) {
var result = {};
_.each(target, function (item, key) {
if (!_.isFunction(item)) {
result[key] = fromJS(item);
}
});
return result;
(function(_){
function makePath(path){
return path.replace(/\[(["']?)([^\1]+?)\1?\]/g, '.$2').replace(/^\./, '').split('.');
};
_.mixin({
get: function (obj, path, defaultValue) {
if (_.isString(path)) {
path = split(path);
}
@miguelludert
miguelludert / get.js
Last active August 29, 2015 14:19
get/set by path
function get(obj, path, defaultValue) {
if (typeof path === "string") {
path = path.replace(/\[(["']?)([^\1]+?)\1?\]/g, '.$2').replace(/^\./, '').split('.');
}
// end of the line (found nothing)
if (obj === undefined) {
return defaultValue;
}
@miguelludert
miguelludert / column doesn't exist.sql
Last active August 29, 2015 14:25
Drop if exists (SQL SERVER)
IF NOT EXISTS(SELECT * FROM sys.columns WHERE Name = N'columnName' AND Object_ID = Object_ID(N'tableName'))
BEGIN
-- Column Exists
END
var React = require("react");
var ReactDOM = require("react-dom");
var _ = require('lodash');
/*
This component is meant to facilitate side to side slide transitions.
It's props are:
goToIndex : the index of the slide to show, REQUIRED
duration : the duration of the sliding, REQUIRED
easing : the css easing type, also known as the transition-timing-fuction, DEFAULTS to 'ease-in-out'
var r=[],i=1;for(;i<101;i++)r.push(((i%3?'':'fizz')+((i%5)?'':'buzz'))||i);console.log(r);
@miguelludert
miguelludert / Modal.jsx
Created April 4, 2016 18:52
Quick modal for React
var React = require('react');
var ReactDOM = require('react-dom');
var document = global.document;
module.exports = React.createClass({
componentDidMount : function() {
this.node = document.getElementById('component-modal-overlay');
if(!this.node){
this.node = document.createElement("div");
this.node.id = 'component-modal-overlay'
@miguelludert
miguelludert / virtualenv.sh
Last active September 3, 2016 00:14
Set up virtualenv
virtualenv --no-site-packages ./
. bin/activate
pip install nodeenv
nodeenv --node=X.X.X -p
npm install -g npm
git clone [email protected]:your-user/ua-b2c.git
@miguelludert
miguelludert / Injection.cs
Created December 28, 2016 19:37
Minimal Dependency Injection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ThinkingSites
{
public class Injection
{
private static Dictionary<Type, Func<object>> Registry = new Dictionary<Type, Func<object>>();