Skip to content

Instantly share code, notes, and snippets.

View camarin24's full-sized avatar

Cristian Marín camarin24

  • Iluma
  • Medellín, Colombia
  • 03:24 (UTC -05:00)
View GitHub Profile
@camarin24
camarin24 / AsyncHelpers.cfm
Last active June 2, 2017 20:15
synchronously
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Web.Helpers
{
public static class AsyncHelpers
{
@camarin24
camarin24 / reflection.cs
Created December 27, 2016 21:52
Reflection Extension Method
private T DeserializeYahooRequest<T>(string response) where T : class, new()
{
T model = new T();
string[] parameters = response.Split('&');
foreach (var item in parameters)
{
var elem = item.Split('=');
PropertyInfo propertyInfo = model.GetType().GetProperty(elem[0]);
propertyInfo.SetValue(model, Convert.ChangeType(elem[1], propertyInfo.PropertyType), null);
}
@camarin24
camarin24 / BaseRepository.cs
Created December 20, 2016 18:38
BaseDbContextManager
public interface IRepository<T> where T : class
{
IQueryable<T> All { get; }
T Delete(T entity);
T FindById(object Id);
T Insert(T entity);
T Update(T entity, T oldEntity, out bool modified);
}
public abstract class BaseEFRepository<TEntity> : IRepository<TEntity> where TEntity : class, new()
@camarin24
camarin24 / Paginate.cs
Created December 19, 2016 15:36
Linq extension method (Paginate)
public static class LinqExtension
{
public static List<T> Paginate<T>(this List<T> data, Func<T, object> orderBy, int pageSize, int PageNumber)
{
var model = data.OrderBy(orderBy).Skip((PageNumber - 1) * pageSize).Take(pageSize).ToList();
return model;
}
}
@camarin24
camarin24 / LinqExtension.cs
Created December 17, 2016 17:43
Linq extension method (converto to int array)
public static class LinqExtension
{
public static int[] ConvertToArrayInt<T>(this List<T> data, Func<T,int> lamba)
{
return data.Select(lamba).ToArray();
}
}
@camarin24
camarin24 / InterfacesImplementations.ts
Created November 22, 2016 19:09
TypeScript Interfaces implementations
interface IRepository<T>{
Delete(Entity:T):T;
Update(Entity:T):T;
Create(Entity:T):T;
}
class IComprasRepository implements IRepository<ComprasModel>{
private _url:string;
constructor(url:string){
this._url = url;
}
@camarin24
camarin24 / Server.js
Created October 10, 2016 15:15
Insert whit Mysql DataBase and Node.js
app.post("/registro", function (req, res) {
var datos = {
nombre: req.body.nombre,
apellido: req.body.apellido,
fecha_nacimiento: req.body.fechaNacimiento,
correo_electronico: req.body.email,
contrasenia: req.body.password
};
db.query("SELECT * FROM personas WHERE correo_electronico = ?", [req.body.email], function (err, user) {
if (err) throw err;