Skip to content

Instantly share code, notes, and snippets.

View mii9000's full-sized avatar

ibrahim mii9000

View GitHub Profile
@mii9000
mii9000 / dynamicwebapirepo.cs
Last active August 29, 2015 14:06
Thin convention based WebAPI repository
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Net.Http;
using System.Threading.Tasks;
using System.Net.Http.Headers;
namespace WebApp
@mii9000
mii9000 / clear.bat
Created December 1, 2014 13:04
remove-aspnet-tempcache
@ECHO OFF
ECHO Performing IIS Reset
IISRESET
ECHO Deleting Cache
FOR /D %%i IN (%LOCALAPPDATA%\Microsoft\WebsiteCache\*) DO RD /S /Q "%%i"
DEL /Q %LOCALAPPDATA%\Microsoft\WebsiteCache\*.*
FOR /D %%i IN (%LOCALAPPDATA%\Temp\VWDWebCache\*) DO RD /S /Q "%%i"
DEL /Q %LOCALAPPDATA%\Temp\VWDWebCache\*.*
@mii9000
mii9000 / ideas.md
Last active August 29, 2015 14:28 — forked from tsaqib/ideas.md
Ideas that you can use for hackathons, competitions and research.

Ideas

I have collected and moderated these ideas from various public sources and put into one place so that problem solvers and solution developers may find inspirations. Because I wish to update it regularly, I have setup as a single page wiki. You may try these ideas on hackathons/competitions/research; some are quite intense problems and some are not. Many of the problems were prepared keeping Dhaka/Bangladesh in mind, but of course can be applied to just about any underdeveloped/developing and sometimes developed countries.

Categories:
  • Eradicate Extreme Poverty and Hunger
  • Education
  • Healthcare
  • Governance
@mii9000
mii9000 / gist:d5e6405233d749a3d5a2
Created October 23, 2015 17:27 — forked from dshookowsky/gist:6529765
Reader object to expando
private dynamic SqlDataReaderToExpando(DbDataReader reader)
{
var expandoObject = new ExpandoObject() as IDictionary<string, object>;
for (var i = 0; i < reader.FieldCount; i++)
expandoObject.Add(reader.GetName(i), reader[i]);
return expandoObject;
}
@mii9000
mii9000 / player.js
Created November 8, 2015 21:02 — forked from revolunet/player.js
basic nodejs mp3 player
var async = require('async');
var lame = require('lame');
var fs = require('fs');
var Speaker = require('speaker');
var volume = require("pcm-volume");
var audioOptions = {
channels: 2,
bitDepth: 16,
sampleRate: 44100,
@mii9000
mii9000 / WinRTXamlQueryExtensions.cs
Last active November 27, 2015 11:25
Extensions method that searches up or down VisualTree from the source element
public static class WinRTXamlQuery
{
/// <summary>
/// Searches descendants recursively down to the last one
/// </summary>
/// <typeparam name="T">FrameworkElement type expected</typeparam>
/// <param name="Source">FrameworkElement searched from</param>
/// <param name="Name">Name of the control to expect</param>
public static IEnumerable<T> GetDescendents<T>(this FrameworkElement Source, string Name = "")
{
@mii9000
mii9000 / ReflectionDbSet.cs
Created March 24, 2016 14:25
Example of using Reflection to set DbSets passing in same DbContext to repositories. P.S. DI was not used in this project this had to resort to this.
//Gets the DbSets and sets their properties to equivalent instances passing in same DbContext
this.GetType().GetProperties()
.Where(p => p.PropertyType.GetGenericTypeDefinition() == typeof(GenericRepository<>))
.ToList()
.ForEach(dbset =>
{
Type EntityType = dbset.PropertyType.GenericTypeArguments[0];
Type GenericRepoType = dbset.PropertyType.GetGenericTypeDefinition().MakeGenericType(EntityType);
ConstructorInfo ctor = GenericRepoType.GetConstructor(new[] { typeof(ApplicationDbContext) });
object GenericRepoInstance = ctor.Invoke(new object[] { DbContext });
@mii9000
mii9000 / ModelStateActionFilter.cs
Created March 24, 2016 14:31
Instead of checking for ModelState is valid or not in every action, encapsulate this check in a Action Filter.
public class ValidateModelAttribute: ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.Controller.ViewData.ModelState.IsValid)
{
return;
}
filterContext.Result = new ViewResult
@mii9000
mii9000 / WebConfigFont.xml
Created March 24, 2016 14:35
Fonts not being served from ASP.NET MVC app hosted in IIS which can be resolved by adding the following inside web.config's system.webServer element.
<staticContent>
<mimeMap fileExtension=".woff2" mimeType="font/x-woff" />
</staticContent>
@mii9000
mii9000 / common-fail-handle.js
Created March 24, 2016 14:52
Common error handler for same type of Promise returning functions
aFunctionThatReturnPromise({ shiftid: event.shiftId, status: 'approve' })
.done(function () {
//Do somehting when the promise succeeds
})
.fail(failHandler);
//Common function for fail handling
function failHandler(msg, res){
alert(msg);