Skip to content

Instantly share code, notes, and snippets.

View miguelludert's full-sized avatar

Miguel Ludert miguelludert

View GitHub Profile
var r=[],i=1;for(;i<101;i++)r.push(((i%3?'':'fizz')+((i%5)?'':'buzz'))||i);console.log(r);
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'
@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
@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;
}
(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 / 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;
@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 / formatAddress.js
Created June 18, 2014 15:58
format address function
function formatAddress(obj, context) {
// this allows you to pass in a context and keys instead of values
if (arguments.length >= 2) {
if (context) {
obj = {
address: _.map(obj.address, function (item) {
return context[item];
}),
city: context[obj.city],
@miguelludert
miguelludert / dynami order by.cs
Created April 22, 2014 14:28
Dynamic Order By
public static IOrderedQueryable<T> OrderBy<T>(this IQueryable<T> source, string property)
{
return ApplyOrder<T>(source, property, "OrderBy");
}
public static IOrderedQueryable<T> OrderByDescending<T>(this IQueryable<T> source, string property)
{
return ApplyOrder<T>(source, property, "OrderByDescending");
}
public static IOrderedQueryable<T> ThenBy<T>(this IOrderedQueryable<T> source, string property)
{
// overrwrite the built in text binding handler to allow for formatting
var origTextHandler = ko.bindingHandlers.text;
var newTextHandler = {
init: origTextHandler.init,
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var bindings = allBindings();
if (bindings.format) {